Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> A bit more complicated than that
> You can do a running total with analytic functions, a simple example being:
>
>SQL> select * from sales;
>
> YEAR AMOUNT
>---------- ----------
> 1 3
> 2 4
> 3 5
>
>SQL> select year,
> 2 amount,
> 3 sum(amount) over (order by year rows unbounded preceding)
>running_total
> 4 from sales
> 5 order by year;
>
> YEAR AMOUNT RUNNING_TOTAL
>---------- ---------- -------------
> 1 3 3
> 2 4 7
> 3 5 12
>
> Just alter the expression in the sum() to include or exclude whatever fields
>you want.
>
its not just a runnin total. in your example the amount is set just for the
1st year i.e. year 1 = 3. the the amount for year 2 would be 3 + something
(say 2) giving 5
year amouint tax total
1 3 2 5 2 5 2 7 3 7 1 8
see how the total for row 1 becomes amount for year 2/ Received on Sun Jan 12 2003 - 21:57:29 CST