running total subquery sorting

0

Please login or register to vote for this query.

(click on this box to dismiss)

Anime and Manga

Q&A for anime and manga fans

declare @t table(Col1 int, Col2 int)

insert into @t values
(5, 3),
(4, 20),
(3, 5),
(2, 10),
(1, 10)

select * from
(
select top 1000000000000000000 t1.Col1, t1.Col2, SUM(t2.Col2) as runningtotal
from @t t1
inner join @t t2 on t1.Col1 >= t2.Col1
group by t1.Col1, t1.Col2
order by t1.Col1
) ss
where runningtotal <= 25

Enter Parameters

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