SUM
functionsupportedCore SQL functionsReturns the sum of non-NULL records for expr. You can use the DISTINCT keyword to compute the sum of unique non-null values. If all records inside a group are NULL, the function returns NULL.
Syntax
supportedpartialnot supportednot scored
Aggregate function
SUM( [ DISTINCT ] <expr1> )
Window function
SUM( [ DISTINCT ] <expr1> ) OVER (
[ PARTITION BY <expr2> ]
[ ORDER BY <expr3> [ { ASC | DESC } ] [ NULLS { FIRST | LAST } ] [ <window_frame> ] ]
)
Parameters
| Name | Required | Description |
|---|---|---|
expr1 | required | This is an expression that evaluates to a numeric data type (INTEGER, FLOAT, DECIMAL, etc.). |
expr2 | required | This is the optional expression to partition by. |
expr3 | required | This is the optional expression to order by within each partition. (This does not control the order of the entire query output.) |
Usage notes
- Numeric values are summed into an equivalent or larger data type.
- When passed a VARCHAR expression, this function implicitly casts the input to floating point values. If the cast cannot be performed, an error is returned.
- When this function is called as a window function with an OVER clause that contains an ORDER BY clause: A window frame is required. If no window frame is specified explicitly, the following implied window frame is used: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW For more information about window frames, including syntax, usage notes, and examples, see Window function syntax and usage.
- The DISTINCT keyword cannot be used.