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
SUM
function is computed over an empty table in whichGROUP BY
is not used,SUM
returnsNULL
. -
If the
SUM
function is computed over an empty group or an empty grouped table (GROUP BY
is used),SUM
returns 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 isNUMBER
with 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
AnalyticClause
in your query, thenSUM
acts as an aggregate function. -
If you specify
DISTINCT
and theAnalyticClause
, then you can only specify theQueryPartitionClause
. TheOrderByClause
andWindowingClause
are not allowed.
Examples
Sum all employee salaries:
Command> SELECT SUM(salary) Total FROM employees; TOTAL < 691400 > 1 row found.