select deptno,ename,sal,
sum(sal) over (partition by deptno order by sal,ename) CumDeptTot,
sum(sal) over (partition by deptno) SalByDept,
sum(sal) over (order by deptno, sal) CumTot,
sum(sal) over () TotSal
from emp
order by deptno, sal
and the result looks like this:
deptno | ename | sal | CumDeptTot | SalByDept | CumTot | TotSal |
10 | John | 1300 | 1300 | 3400 | 1300 | 11300 |
10 | Michael | 1100 | 2400 | 3400 | 2400 | 11300 |
10 | Robert | 1000 | 3400 | 3400 | 3400 | 11300 |
20 | Vicky | 1200 | 1200 | 3550 | 4600 | 11300 |
20 | Sally | 1250 | 2450 | 3550 | 5850 | 11300 |
20 | Harry | 1100 | 3550 | 3550 | 6950 | 11300 |
30 | Pavel | 1400 | 1400 | 4350 | 8350 | 11300 |
30 | Dennis | 1400 | 2800 | 4350 | 9750 | 11300 |
30 | Barbie | 1550 | 4350 | 4350 | 11300 | 11300 |
No comments:
Post a Comment