1.基础语法
1.select …A… from …B… where …C…
A:列名
B:表明
C:筛选条件
如果该表是一个分区表,则where条件中必须对分区字段进行限制。
2.group by … having
3.常用聚合函数
1.count():计数 count(distinct … …)去重计数
2.sum():求和
3.avg():平均值
4.max():最大值
5.min():最小值
4.order by
2.执行顺序
from–>join–>on–>where–>group by–>with–>having–>select–>distinct–>order by–>limit
3.常用函数
1.将时间戳转化为日期
from_unixtime(bigint unixtime,‘string format’)
format:
1.yyyy-MM-dd hh:mm:ss MM代表月份,mm代表分钟
2.yyyy-MM-dd HH:mm:ss HH代表24小时制,hh代表12小时制
3.yyyy-MM-dd hh
4.yyyy-MM-dd
转化成标准的形式后可以用to_date(),year(),month()等函数获取日期、年、月等
2.计算日期间隔
datedif