find cumulative sum of previous columns
770730Nov 8 2010 — edited Nov 9 2010Hi,
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