declare @t table ([Name] varchar(1), Amount int) insert i...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Ask Ubuntu

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, t2.[Name], t2.Amount

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results