What aggregate functions do
An aggregate function collapses many rows into a single value per group — a sum,
an average, a row count, a concatenated string. They pair with GROUP BY to
produce one result row per group, or run over the whole table with no GROUP BY.
This reference lists the common aggregates, their NULL behaviour, and which of
MySQL, PostgreSQL, SQLite and SQL Server support each name.
How it works
Each aggregate scans the rows of a group and folds them into one value, ignoring
NULL inputs (except COUNT(*)):
SELECT department,
COUNT(*) AS headcount,
AVG(salary) AS avg_salary,
SUM(DISTINCT bonus) AS unique_bonus_total,
STRING_AGG(name, ', ') AS roster
FROM employees
GROUP BY department;
DISTINCT inside an aggregate restricts it to unique values. String aggregation
is the least portable area: MySQL/SQLite spell it GROUP_CONCAT while
PostgreSQL/SQL Server use STRING_AGG. The tool filters the table as you type
and flags which databases provide each function.
Tips and notes
COUNT(*)never returns NULL; the all-NULL group still counts its rows.AVGof an empty or all-NULL set isNULL, not0— wrap inCOALESCEif needed.- Mixing aggregated and non-aggregated columns requires every plain column in
GROUP BY. FILTER (WHERE ...)(Postgres/SQLite) is a cleaner alternative toSUM(CASE WHEN ...).