-Analytical functions in Oracle.
SELECT rownum ,
SUM(rownum) over (order by rownum rows BETWEEN unbounded preceding AND CURRENT row) AS running_total , (rownum * (rownum+1))/2 as formula
FROM dual
CONNECT BY rownum < 11;
The above can be used with a real table. The order by can be any columns that you wish to order the rows by and sum() can be on a column that you wish to calculate running total on.
SELECT rownum ,
SUM(rownum) over (order by rownum rows BETWEEN unbounded preceding AND CURRENT row) AS running_total , (rownum * (rownum+1))/2 as formula
FROM dual
CONNECT BY rownum < 11;
The above can be used with a real table. The order by can be any columns that you wish to order the rows by and sum() can be on a column that you wish to calculate running total on.