Hi forum,
I'd like to keep the track of the following orders from this table using a select statement rather than a PL/SQL block
Is there a way to keep track of the running total as I add to my quantity with BUY and reduce my quantity with SELL. In PL/SQL I would return the data to a cursor,
loop through the data and add or subtract depending on a buy or sell using an IF statement. Is there a way to do this using a SELECT statement. I need to track the moving total.
I know there is a cumulative function in oracle but that assumes the next value is additive. Trying to calculate RUNNING_TOTAL from ORDER_AMOUNT
BUY/SELL | ORDER_AMOUNT | RUNNING_TOTAL |
---|
BUY | 10 | 10 |
BUY | 15 | 25 |
BUY | 10 | 35 |
BUY | 20 | 55 |
SELL | 30 | 25 |
SELL | 15 | 10 |
SELL | 5 | 5 |
BUY | 1 | 6 |
BUY | 50 | 56 |