How to get cumulative sum

前端 未结 16 2546
遇见更好的自我
遇见更好的自我 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条回答
  •  余生分开走
    2020-11-22 04:06

    Without using any type of JOIN cumulative salary for a person fetch by using follow query:

    SELECT * , (
      SELECT SUM( salary ) 
      FROM  `abc` AS table1
      WHERE table1.ID <=  `abc`.ID
        AND table1.name =  `abc`.Name
    ) AS cum
    FROM  `abc` 
    ORDER BY Name
    

提交回复
热议问题