SUM
Finds the total of all values in the argument. Null values are ignored. SUM is an aggregate function. SUM can also be an aggregate analytic function. See "Aggregate Functions" for more details on aggregate functions. See "Analytic Functions" for more information on analytic functions.
SQL syntax
SUM ([ALL | DISTINCT] Expression) [OVER ([AnalyticClause])]Parameters
SUM has the parameters:
| Parameter | Description |
|---|---|
|
|
Can be any numeric data type or any nonnumeric data type that can be implicitly converted to a numeric data type. |
|
|
Includes any duplicate rows in the argument of an aggregate function. If neither |
|
|
Eliminates duplicate column values from the argument of an aggregate function. |
|
|
If specified, indicates aggregate analytic function. See "Analytic Functions" for more information on analytic functions. |
Description
-
If the
SUMfunction is computed over an empty table in whichGROUP BYis not used,SUMreturnsNULL. -
If the
SUMfunction is computed over an empty group or an empty grouped table (GROUP BYis used),SUMreturns nothing. -
If the source is
TT_TINYINT,TT_SMALLINT, orTT_INTEGER, the result data type isTT_BIGINT. -
If the source is
NUMBER, then the result data type isNUMBERwith undefined scale and precision. -
For all other data types, the result data type is the same as the source.
-
If you do not use the
AnalyticClausein your query, thenSUMacts as an aggregate function. -
If you specify
DISTINCTand theAnalyticClause, then you can only specify theQueryPartitionClause. TheOrderByClauseandWindowingClauseare not allowed.
Examples
Sum all employee salaries:
Command> SELECT SUM(salary) Total FROM employees; TOTAL < 691400 > 1 row found.