Part1:求累加和
-- 方法一:sum() over函数
select month_id,sum(num) over(order by month_id)
from public.test_sum_over;
-- 方法二:列子查询
select month_id
,(select sum(num) from public.test_sum_over t2 where t2.month_id<=t1.month_id)
from public.test_sum_over t1
Part1:求累加和
-- 方法一:sum() over函数
select month_id,sum(num) over(order by month_id)
from public.test_sum_over;
-- 方法二:列子查询
select month_id
,(select sum(num) from public.test_sum_over t2 where t2.month_id<=t1.month_id)
from public.test_sum_over t1
本文标题:SQL 计算月累计的两个方法
本文链接:https://www.haomeiwen.com/subject/qkdeuhtx.html
网友评论