Is it possible to get compounded sum in sql server? e.g.
Month Salary Total
Jan 1000 1000
Feb 1200 2200
Mar 1000 3200
. . .
. . .
Please help.
Is it possible to get compounded sum in sql server? e.g.
Month Salary Total
Jan 1000 1000
Feb 1200 2200
Mar 1000 3200
. . .
. . .
Please help.
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