admin管理员组文章数量:1612097
背景
数据如上,按id和ssny分组,求最大的开票时间,若为空,取非空的上一期组内最大开票时间
解
SELECT
id,
ssny,
kpsj,
max(kpsj) OVER(PARTITION BY id ORDER BY ssny desc ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) zwkpsj
from a;
即为所得
拓展
sum(…A…) over(partition by …B… order by …C… rows between … D1… and …D2…)
avg(…A…) over(partition by …B… order by …C… rows between … D1… and …D2…)
A:需要被加工的字段名称
B:分组的字段名称
C:排序的字段名称
D:计算的行数范围
rows between unbounded prceding and current row --包括本行和之前所有的行
rows between current row and unbounded following --包括本行和之后所有的行
rows between 3 preceding and current row --包括本行以内和前三行
rows between 3 preceding and 1 following --从前三行到下一行 (5行)
本文标签: 巧用RowsCurrentRowunbounded
版权声明:本文标题:巧用ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1728626837a1166601.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论