over()
1.distinct 2.group by
partition by 子句
over(partition by(condition) order by condition)
window 子句
over(partition by(condition)order by condiiton rows between unbounded preceding and current row)
over(partition by(condition) order by condition rows between 数字 preceding and current row)
over(partition by(condition) order by condition rows between 数字 preceding and 数字 following)
over(partiton by(condition) order by condition rows between current row and unbounded following )
序列函数
ntile(切片)
ntile不支持row between
ntile(需要切成几片的数字) over(partition by(condition)order by(condition))
row_number 对目标进行排序,即使有相同的数字,也会有前后的数字大小顺序,并且数字是连续 的。
rank() 对目标进行排序,当出现相同数字时,会以相同数字排序,但是会留下空位。
即加入第四位和第五位数字大小相同,rank()排序标记相同顺序数字大小,这样会跳过排序5号数字
dense_rank() 与rank()大体相同,区别在于它不会有空位,数字也是连续的,只是相同的数字会打上
相同的排序顺序
lag(condition,数字n) 每一行查询结果返回上n行condition
lag(condition,数字n,string) 每一行返回上n行数据,为空的行则默认string
lead(conditon,数字n,string) 用法与lag相似,返回下n行数据,为空默认string
first_value 截至到当前行的第一个值
first_value(condition)over(partition by(condition) order by(condition))
last_value 截至当前行的最后一个值
last_value(condition)over(partiton by(condition) order by(condition))