SQL> select deptno,empno,sal,sum(sal) over (order by sal) from emp order by 3;
DEPTNO EMPNO SAL SUM(SAL)OVER(ORDERBYSAL)
---------- ---------- ---------- ------------------------
20 7369 800 800
30 7900 950 1750
20 7876 1100 2850
30 7521 1250 5350
30 7654 1250 5350
10 7934 1300 6650
30 7844 1500 8150
30 7499 1600 9750
10 7782 2450 12200
30 7698 2850 15050
20 7566 2975 18025
20 7788 3000 24025
20 7902 3000 24025
10 7839 5000 29025
SQL> select deptno,empno,sal,sum(sal) over (partition by deptno order by sal) from emp order by 3;
DEPTNO EMPNO SAL SUM(SAL)OVER(PARTITIONBYDEPTNOORDERBYSAL)
---------- ---------- ---------- -----------------------------------------
20 7369 800 800
30 7900 950 950
20 7876 1100 1900
30 7654 1250 3450
30 7521 1250 3450
10 7934 1300 1300
30 7844 1500 4950
30 7499 1600 6550
10 7782 2450 3750
30 7698 2850 9400
20 7566 2975 4875
20 7902 3000 10875
20 7788 3000 10875
10 7839 5000 8750
SQL> select deptno,empno,sal,sum(sal) over (partition by deptno) from emp order by 1;
DEPTNO EMPNO SAL SUM(SAL)OVER(PARTITIONBYDEPTNO)
---------- ---------- ---------- -------------------------------
10 7782 2450 8750
10 7839 5000 8750
10 7934 1300 8750
20 7566 2975 10875
20 7902 3000 10875
20 7876 1100 10875
20 7369 800 10875
20 7788 3000 10875
30 7521 1250 9400
30 7844 1500 9400
30 7499 1600 9400
30 7900 950 9400
30 7698 2850 9400
30 7654 1250 9400
SQL> select ename,sal,sum(case when ename = 'MILLER' then sal else -sal end) over (order by sal,empno ) as running_diff from emp where deptno =10;
ENAME SAL RUNNING_DIFF
---------- ---------- ------------
MILLER 1300 1300
CLARK 2450 -1150
KING 5000 -6150