Monday, June 13, 2011

Cumulative Sum in SQL Server

http://stackoverflow.com/questions/2120544/how-to-get-cumulative-sum


declare  @t table (
    id int
,
    SomeNumt int 
)



 
insert into @select 1,10 union select 2,12 union select 3,3 union select 4,15 union select 5,23

 
select * from @




select t1.id, t1.SomeNumt, SUM(t2.SomeNumt) as sum from @t t1 inner join @t t2 on t1.id >= t2.id group by t1.id, t1.SomeNumt order by t1.id 

No comments:

Post a Comment

 using Microsoft.AspNetCore.Mvc; using System.Xml.Linq; using System.Xml.XPath; //<table class="common-table medium js-table js-stre...