Trying to work out a solution for a recently posted question (edit: ).
For columns v1 and v2 in each row, need to find the sum of all values occurring in the subsequent rows
upto a value that is 100 or greater.
with t(id, v1, v2) as
(
select 1, 80 , 20 from dual union all
select 2, 90 , 40 from dual union all
select 3, 130 , 170 from dual union all
select 4, 20 , 30 from dual union all
select 5, 150 , 140 from dual union all
select 6, 30 , 40 from dual union all
select 7, 110 , 110 from dual union all
select 8, 20 , 220 from dual union all
select 9, 130 , 30 from dual
)
select * from t;
expected resultset:
ID V1FRST V1SUM V2FRST V2SUM
---------- ---------- ---------- ---------- ----------
1 80 300 20 230
2 90 220 40 210
3 130 300 170 340
4 20 170 30 170
5 150 290 140 290
6 30 140 40 150
7 110 260 110 330
8 20 150 220 250
9 130 130 30 30
Thanks.