unbounded preceding 起始行
unbounded following 结尾行
current row 当前行
1 preceding 当前行的前1行
1 following 当前行的后1行
首先这是数据格式
1.当前行到最后一行的汇总(逐行递减)
with tt as(
select a.*,sum(mainid)over(rows between current row and unbounded following) as sums
from (
select recid,buyerid,mainid
from bi_edw.edw_crm_jd_sales_tmp
order by recid
limit 4
)a
)
select * from tt
结果:
2.第一行跟当前行的汇总(累加