一、排序窗口函数
窗口函数()over()([partition by 字段名] [order by 字段名 asc|desc])
1、窗口函数只能写在select子句中
2、partition by 子句指定分区依据,只分区不去重,group by 分区且去重
3、排序窗口中order by 子句时必选项,指定排序依据
4、排序窗口函数
-
rank()over() :跳跃式排序 – 数值为99,99,90,排名为1,1,3
-
dense_rank()over():并列连续排名 – 数值为99,99,90 ,排名为1,1,2
-
row_number()over():连续性排名 – 数值为99,99,90, 排名为1, 2,3
二、偏移分析函数
1、lag(字段名,偏移量 [默认值] over([partition by 字段名] order by 字段名 asc|desc)
2、lead(字段名,偏移量 [默认值] over([partition by 字段名] order by 字段名 asc|desc)
3、lag 向上偏移,lead 向下偏移