SQL: How to cumulatively sum up values till a condition is satisfied?
337552Feb 7 2013 — edited Feb 8 2013Hello all,
I need to write a SQL to fulfill a particular requirement.
For each row, the values in Field2 should be cumulatively summed up to see when it will be equal to the value of Field1
Eg. In the following example, Field1 has 15. Field2 values will be summed up cumulatively till they reach 15 (03-JAN-2013)
For the next record Field1 is 8, so Field2 can match 8 on 05-JAN-13.
Day Field1 Field2
01-JAN-2013 15 10
02-JAN-2013 8 4
03-JAN-2013 9 1
04-JAN-2013 12 2
05-JAN-2013 7 2
Can this be achieved through SQL?
Using Analytical Functions?
Please help.
Regards,
Sam
Edited by: sammydude on Feb 7, 2013 5:24 AM