SQL Aggregate Functions
Here’s a clear, complete guide to SQL Aggregate Functions — what they do, how they behave with NULLs, and best-practice examples.
What Are SQL Aggregate Functions?
Aggregate functions take multiple rows and return a single summarized value.
They are often used with GROUP BY.
Common SQL AVG() Functions
1. COUNT()
Counts rows.
-
COUNT(*)counts all rows -
COUNT(column)ignores NULLs
2. SUM()
Adds numeric values.
3. AVG()
Returns the average of numeric values (ignores NULL).
4. MIN() and MAX()
Returns smallest and largest values.
Using Aggregate Functions with GROUP BY
HAVING (Filter After Aggregation)
Use HAVING to filter aggregated results (not WHERE).
Important Behavior Notes
✔ All aggregate functions ignore NULLs, except COUNT(*)
✔ Aggregates without GROUP BY operate on the entire table
✔ Cannot reference non-aggregated columns without GROUP BY
Combining Aggregates
You can compute multiple aggregates at once:
