Oracle has a nice possibility to calculate running totals. Assume we have a sales system where transactions are stored over time. We would like to know the running total – what is sold until a certain transaction.
The code to calculate this is:
SELECT trans_id,to_char(trans_date,'dd-mm-yyyy hh24:mi:ss' ) trans_date , product_code ,qty* price amount, sum(qty* price) over ( order by trans_id ) runing_total from supermarket_trans where trunc(TRANS_DATE)=trunc(sysdate)