【HIVE】窗口函数中数据窗口BUG

本文探讨了Hive窗口函数在使用`sum() over()`配合`rows between`时出现的数据错误,指出仅使用`rows between 1 following and 3 following`会导致计算错误,而添加`rows between unbounded preceding and current row`或`rows between unbounded preceding and unbounded following`可使结果正确。问题可能源于未明确当前行或排序问题。
摘要由CSDN通过智能技术生成

一、问题

1. 单独使用窗口函数sum() over() 计算rows between 1 following and 3 following(假设当前行为x, 数据框应为[x+1, x+3])时,计算结果错误。

sum(value) over(partition by name order by sortcol rows between 1 following and 3 following) as way1

 

2. 前面加入rows between unbounded preceding and current row 时,way1指标计算才正确。

sum(value) over(partition by name order by sortcol) as way01 --有排序时,默认是 rows between unbounded preceding and current row

或者 rows between unbounded prece

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值