22,298
社区成员
发帖
与我相关
我的任务
分享
with tb(月份,金额)as(
select 1,20000 union all
select 2,30000 union all
select 3,5000
)
select 月份,金额,(select sum(金额) from tb t2 where t2.月份<=t1.月份) 累计金额
from
tb t1
with tb(月份,金额)as(
select 1,20000 union all
select 2,30000 union all
select 3,5000
)
select *,(
select SUM(a.金额) from tb a,tb b
where a.月份<=b.月份 and b.月份=c.月份
group by b.月份) 累计金额
from tb c
用视图吧..