SUM is a standard SQL aggregate function that adds together all non-NULL values of a numeric expression. When used without GROUP BY, it returns a single scalar value representing the grand total of the result set. When used with GROUP BY, it computes a separate subtotal for each group. NULL values are ignored. DISTINCT can be specified to add only unique values; ALL (the default) aggregates every non-NULL value. SUM works on integer, decimal, and floating-point types and can also operate on interval types in databases that support them. If the data set is empty or all evaluated values are NULL, the result is NULL, not zero. Because SUM is an aggregate, it cannot be used in a WHERE clause; use HAVING to filter aggregated results. Some systems allow SUM() OVER() window syntax to return running totals without collapsing rows.
DISTINCT
(ALL) - Keyword|||DISTINCT sums only unique non-NULL values; ALL (default) includes all non-NULL valuesnumeric_expression
(Numeric) - Column name or arithmetic expression to aggregateAVG, COUNT, MIN, MAX, GROUP BY, HAVING, WINDOW FUNCTIONS
SQL-92 Standard
SUM works on integer, decimal, numeric, float, real, and in some systems interval types. It ignores non-numeric types.
If every evaluated row is NULL or the result set is empty, SUM returns NULL. Coalesce the result (e.g., COALESCE(SUM(col),0)) if you need zero.
No. Aggregates are evaluated after WHERE. Use HAVING to filter on SUM results.
Include a GROUP BY listing every non-aggregated column, or use a window function to avoid grouping.