This question is an extension of the question here Query to get all records until the sum of column less than or equal a value
For the table: items
Use a cumulative sum and then join:
join
select v.*, i.* from (select i.*, sum(price) over (order by slno) as running_price from items i ) i join values v on i.running_price <= v.value order by v.id, i.slno;
1.4m articles
1.4m replys
5 comments
57.0k users