SUM() GROUP BY ...
All functions > GROUP BY > SUM() GROUP BY ...
Returns the sum of the values in the group.
Syntax
SUM(expr) [ FILTER (WHERE condition) ] [ GROUP BY feature [, feature ...] ]
Notes
- Adds all numeric values in the group
- NULL values are excluded from the calculation
- Returns NULL if all values are NULL or group is empty
- Result type matches input type
- Can overflow for large sums depending on the database engine
- Can be used with WHERE clause to filter before aggregation
- Can be used with GROUP BY clause for grouped aggregation
Examples
FeatureQL
SELECT
f1 := ZIP(ARRAY[1, 2, 3] AS value).TRANSFORM(SELECT SUM(value)).UNWRAP_ONE() -- Sum over one group
;Result
| f1 BIGINT |
|---|
| 6 |