窗口函数笔记

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))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值