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!

find cumulative sum of previous columns

770730Nov 8 2010 — edited Nov 9 2010
Hi,

How do I get the cumulative sum of a particular column in previous rows in the current row.
e.x. I have a table Products,

Date | Orders
__________________
1-JAN-10 | 3
2-JAN-10 | 5
3-JAN-10 | 1

I would like to select the date and orders between 1 and 3rd.Something like ....
Select Date,Orders from Products where Date between to_date('1-JAN-10') and to_date('3-JAN-10')

But I want the output like this...

Date | Orders
__________________
1-JAN-10 | 0
2-JAN-10 | 3
3-JAN-10 | 8

similarly when I select it between 2 and 3rd, I want the output as...

Date | Orders
_________________
2-JAN-10 | 3
3-JAN-10 | 8

and so on. Here in the output, orders is the cumulative sum of previous columns.

Edited by: eric clapton on Nov 8, 2010 8:45 PM
This post has been answered by Frank Kulash on Nov 9 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 7 2010
Added on Nov 8 2010
3 comments
1,840 views