基础的语法
select from where语法
select * from table where 。。。
select distinct * from table where 。。。
order by
order by 单独使用按字段的升序和降序排列
默认升序排列,按照降序排列关键字Desc
group by
group by单独使用
group by和order by结合使用
cast
- 数值类型列转化字符类型列
- 日期或时间类型列转化为日期或者时间
聚合类函数
- left join
- inner join
日期的计算函数
- datediff计算日期间隔
窗口函数的使用方法
- partition by
- over
- row_number()
- lag和lead
注意细节
- 注释的写法:双横线 - -
- 不等于号的书写<>
- 空值的表示 null
- column列非空的表示方法: 。。。 where column is not null and column <>’’
- 匹配中文字符为了避免出现错误,最好有一个N: 。。。where [促销品] = N’是’
- AND&OR的用法
- 模糊匹配:like结合%的用法
推荐W3school的sql教程,网址如下:
http://www.w3school.com.cn/sql/index.asp