ccli555

https://blog.csdn.net/weixin_43332500/article/details/105033468

1、语法:

sum(字段1 ) over (partition by 字段2 order by 字段3 rows between unbounded preceding and current row) as 新字段名

2、功能:

实现组内累加

3. 例子

select name,mon,tota_amount,
sum(tota_amount) over(partition by name order by mon rows between unbounded preceding and current row) as account
from
(select name,mon,sum(amount) as tota_amount
from sheet1
group by name,mon) as a

select name,mon,tota_amount,
sum(tota_amount) over(partition by name order by mon rows between unbounded preceding and current row) as account
from
(select name,mon,sum(amount) as tota_amount
from sheet1
group by name,mon) as a

4、函数说明
sum(tota_amount)的求和是针对后面over()窗口的求和,
over中partition by name order by mon 针对name这一组按照月份排序,
rows between unbounded preceding and current row 限定了行是按照在当前行不限定的往前处理,通俗就是处理当前以及之前的所有行的sum,即3月时sum(amount)求的时1、2、3月的和,2月时sum(amount)求的是1、2月的和。unbounded意思无限的 preceding在之前的,current row当前行。

分类:

技术点:

相关文章:

  • 2021-05-12
  • 2021-08-05
  • 2021-06-16
  • 2021-11-23
  • 2022-12-23
  • 2021-04-27
  • 2022-12-23
  • 2021-12-10
猜你喜欢
  • 2021-11-03
  • 2021-12-17
  • 2021-12-10
  • 2022-12-23
  • 2021-08-01
  • 2021-12-28
  • 2021-06-22
相关资源
相似解决方案