关于oracle 开窗函数--1
一.OVER
1.SQL> SELECT deptno,ename,sal FROM emp ORDER BY deptno,ename;
DEPTNO ENAME SAL
---------- ---------- ----------
10 CLARK 2450
10 KING 5000
10 MILLER 1300
20 FORD 3000
20 JONES 2975
20 SMITH 800
30 ALLEN 1600
30 BLAKE 2850
30 JAMES 950
30 MARTIN 1250
30 TURNER 1500
30 WARD 1250
已选择12行。
2.SQL> SELECT deptno,ename,sal,
2 SUM(sal) OVER(ORDER BY ename) 连续求和,
3 SUM(sal) OVER() 总和, --等效于SUM(sal)
4 100*ROUND(sal/SUM(sal) OVER(),4) "份额(%)"
5 FROM emp;
DEPTNO ENAME SAL 连续求和 总和 份额(%)
---------- ---------- ---------- ---------- ---------- ----------
30 ALLEN 1600 1600 24925 6.42
30 BLAKE 2850 4450 24925 11.43
10 CLARK 2450 6900 24925 9.83
20 FORD 3000 9900 24925 12.04
30 JAMES 950 10850 24925 3.81
20 JONES 2975 13825 24925 11.94
10 KING 5000 18825&nbs