How to get cumulative sum

前端 未结 16 2559
遇见更好的自我
遇见更好的自我 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条回答
  •  Happy的楠姐
    2020-11-22 04:06

    You can use this simple query for progressive calculation :

    select 
       id
      ,SomeNumt
      ,sum(SomeNumt) over(order by id ROWS between UNBOUNDED PRECEDING and CURRENT ROW) as CumSrome
    from @t
    

提交回复
热议问题