SQL AGGREGATE represents the family of built-in functions (SUM, COUNT, AVG, MIN, MAX, ARRAY_AGG, etc.) that reduce a set of rows to one value. They are most often paired with GROUP BY to return one result per group, but they also work without GROUP BY to aggregate an entire table or subquery. Aggregate functions ignore NULL values unless stated otherwise (e.g., COUNT(*) counts NULLs, while COUNT(column) does not). DISTINCT can be added to aggregate only unique values. Some databases allow custom aggregates through CREATE AGGREGATE. Aggregates cannot normally appear in WHERE clauses; use HAVING for post-aggregation filters. They are deterministic when the underlying data is unchanged.
AGG_FUNCTION
(identifier) - Name of the aggregate function such as SUM, COUNT, AVG, MIN, MAX, ARRAY_AGGexpression
(any) - Column or expression to aggregateDISTINCT/ALL
(keyword) - OPTIONAL. DISTINCT aggregates unique values; ALL (default) aggregates all non-NULL valuesGROUP BY, HAVING, WINDOW FUNCTIONS, CREATE AGGREGATE, DISTINCT, COUNT, SUM, AVG
SQL-92 standard
Aggregate functions calculate a single result from a set of rows. Examples include SUM, COUNT, AVG, MIN, and MAX.
Use GROUP BY when you need a separate aggregated value for each subgroup of your data rather than one value for the entire result set.
Yes. COUNT(*) counts every row. To exclude NULLs, use COUNT(column) which ignores rows where column is NULL.
Yes. Use the HAVING clause, not WHERE, to filter based on aggregate values after grouping.