A Simple Example of Oracle Analytics: Running Totals

Kevin Meade's picture
articles: 

Comments

dr.s.raghunathan's picture

Thanks a lot. Analytics are really amazing.


select
ename, raise_date, raise_amount
-- Forward
, sum(raise_amount) over(partition by ename order by raise_date asc) as running_total1a
, sum(raise_amount) over(partition by ename order by raise_date rows between unbounded preceding and current row) as running_total1b
-- Backward
, sum(raise_amount) over(partition by ename order by raise_date desc) as running_total2a
, sum(raise_amount) over(partition by ename order by raise_date rows between current row and unbounded following) as running_total2b
-- Parent group
, sum(raise_amount) over(partition by ename order by raise_date rows between unbounded preceding and unbounded following) as total
-- Percent of Total
, (sum(raise_amount) over(partition by ename order by raise_date asc) / sum(raise_amount) over(partition by ename order by raise_date rows between unbounded preceding and unbounded following))*100 || ' %' as market_share
from emp_raise_hist
order by ename, raise_date;