How to get cumulative sum

前端 未结 16 2374
遇见更好的自我
遇见更好的自我 2020-11-22 03:32
declare  @t table
    (
        id int,
        SomeNumt int
    )

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


        
16条回答
  •  梦毁少年i
    2020-11-22 04:22

    Once the table is created -

    select 
        A.id, A.SomeNumt, SUM(B.SomeNumt) as sum
        from @t A, @t B where A.id >= B.id
        group by A.id, A.SomeNumt
    
    order by A.id
    

提交回复
热议问题