Oracle8i SQL Reference Release 2 (8.1.6) A76989-01 |
|
Functions, 93 of 121
For information on syntax and semantics, see "Analytic Functions".
SUM
returns sum of values of expr. You can use it as an aggregate or analytic function.
The following example calculates the sum of all salaries in the EMP
table:
SELECT SUM(sal) "Total" FROM emp; Total ---------- 29025
The following example calculates, for each manager, a cumulative total of salaries of employees who answer to that manager that are equal to or less than the current salary:
SELECT mgr, ename, sal, SUM(sal) OVER (PARTITION BY mgr ORDER BY sal RANGE UNBOUNDED PRECEDING) l_csum FROM emp; MGR ENAME SAL L_CSUM ---------- ---------- ---------- ---------- 7566 SCOTT 3000 6000 7566 FORD 3000 6000 7698 JAMES 950 950 7698 WARD 1250 3450 7698 MARTIN 1250 3450 7698 TURNER 1500 4950 7698 ALLEN 1600 6550 7782 MILLER 1300 1300 7788 ADAMS 1100 1100 7839 CLARK 2450 2450 7839 BLAKE 2850 5300 7839 JONES 2975 8275 7902 SMITH 800 800 KING 5000 5000
|
![]() Copyright © 1999 Oracle Corporation. All Rights Reserved. |
|