SUM

functionsupportedCore SQL functions

docs.snowflake.com ↗

Data metric functionsAggregate functionsWindow function syntax and usage

Returns 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

NameRequiredDescription
expr1requiredThis is an expression that evaluates to a numeric data type (INTEGER, FLOAT, DECIMAL, etc.).
expr2requiredThis is the optional expression to partition by.
expr3requiredThis is the optional expression to order by within each partition. (This does not control the order of the entire query output.)

Usage notes

See also

Referenced by