1 / 8

PostgreSQL · Joins & aggregations

Reduce many rows to one group result

An aggregate computes one value from a set of input rows. count, sum, min, max, and avg are common examples. Without GROUP BY, an aggregate summarizes the whole filtered input.

SELECT count(*) AS order_count
FROM orders
WHERE status = 'paid';

WHERE chooses the input rows before the aggregate runs. If no rows qualify, count returns 0; most other built-in aggregates return NULL for an empty input set.