gpt4 book ai didi

sql - SQL Server 中的复合 SUM

转载 作者:行者123 更新时间:2023-12-03 09:25:14 26 4
gpt4 key购买 nike

能否在sql server中求复合和?例如

月工资总计

一月 1000 1000

二月 1200 2200

三月 1000 3200

。 。 .

。 。 .

请帮忙。

最佳答案

Declare @t table( Months varchar(10), Salary int) 
insert into @t
select 'Jan', 1000 union all
select 'Feb', 1200 union all
select 'Mar', 1000
;With CTE as
(
select *,ROW_NUMBER()over(order by (select null))rn from @t
)
,CTE1 as
(
select a.*,salary [Total] from CTE a where rn=1
union all
select a.*,a.Salary+Total from CTE a inner join CTE1 b on a.rn-b.rn=1
)
select * from cte1

关于sql - SQL Server 中的复合 SUM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22299422/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com