Q&A for Ubuntu users and developers
declare @t table ([Name] varchar(1), Amount int) insert into @t values ('a', 100) insert into @t values ('b', 300) insert into @t values ('c', 250) ; with temp (name, amount, rn) as ( select name , amount , row_number() over (order by Amount) as rn from @t ) select t1.[Name], t1.Amount, sum(t1.Amount) from temp t1 join temp t2 on t1.rn <= t2.rn group by t1.[Name], t1.Amount order by [Name]