over()
over() 函数在Hive中运用广泛,通常搭配row_number() ,min(),max(),sum()来使用,总结下over函数划定窗口的范围
SELECT
id,
name,
num,
sum(num) over() sum1
from
aa
也就是每一行后面的sum1是对所有行的num进行sum(num)操作,如果设置好窗口范围,每一行后面的结果是对以当前行为中心按照窗口范围内的行进行sum(num)操作得出结果。一下会有对应的案例
SELECT
id,
name,
num,
sum(num) over(order by id) sum1
from
aa
SELECT
id,
name,
num,
sum(num) over(partition by name) sum1
from
aa
SELECT
id,
name,
num,
sum(num) over(partition by name order by id) sum1
from
aa
SELECT
id,
name,
num,
sum(num) over( order by id range between 1 preceding and 1 following ) sum1
from
aa
SELECT
id,
name,
num,
sum(num) over( order by id range between CURRENT ROW AND 1 following ) sum1
from
aa
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/d_l_w_d_l_w/article/details/120647282
内容来源于网络,如有侵权,请联系作者删除!