Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQL: How to cumulatively sum up values till a condition is satisfied?

337552Feb 7 2013 — edited Feb 8 2013
Hello 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2013
Added on Feb 7 2013
6 comments
2,888 views