oracle累积求和分析函数sum over的使用

示例1: select deptno,ename,job,sal,sum(sal) over(order by sal) he from emp; 结果: 20 SMITH CLERK 800 800 30 JAMES CLERK 950 1750 20 ADAMS CLERK 1100 2850 30 WARD SALESMAN 1250 5350 30 MARTIN SALESMAN 1250 5350 10 MILLER CLERK 1300 6650 30 TURNER SALESMAN 1500 8150 30 ALLEN SALESMAN 1600 9750 示例2: select deptno,ename,sal,sum(sal) over(partition by deptno order by ename) he from emp; 结果: 10 CLARK 2450 2450 10 KING 5000 7450 10 MILLER 1300 8750 20 ADAMS 1100 1100 20 FORD 3000 4100 20 JONES 2975 7075 20 SCOTT 3000 10075 20 SMITH 800 10875 30 ALLEN 1600 1600 30 BLAKE 2850 4450   

 

 

你可能感兴趣的:(数据库)