Example: Calculate cumulative sum

This query calculates a cumulative sum of salary per department and ORDER BY start_date.

SELECT dept_id, start_date, name, salary,
  SUM(salary) OVER (PARTITION BY dept_id ORDER BY
  start_date ROWS BETWEEN UNBOUNDED PRECEDING AND
  CURRENT ROW) 
FROM emp1 
ORDER BY dept_id, start_date;

The following are the results from the above query:

dept_id  start_date    name     salary   sum(salary)
-------  ----------    ----     ------   -----------
100      1996-01-01    Anna      18000        18000
100      1997-01-01    Mike      28000        46000
100      1998-01-01    Scott     29000        75000
100      1998-02-01    Antonia   22000        97000
100      1998-03-12    Adam      25000       122000
100      1998-12-01    Amy       18000       140000
200      1998-01-01    Jeff      18000        18000
200      1998-01-20    Tim       29000        47000
200      1998-02-01    Jim       22000        69000
200      1999-01-10    Tom       28000        97000
300      1998-03-12    Sandy     55000        55000
300      1998-12-01    Lisa      38000        93000
300      1999-01-10    Peter     48000       141000