Skip to content
Commitwise
Menu

Aggregate function

Also called: Aggregate

A SQL function that turns many rows into one value: count, sum, avg, min, max.

Definition

Without GROUP BY an aggregate returns one row for the whole result; with GROUP BY, one row per group. All aggregates except count(*) skip NULL values, and over zero rows they return NULL (count returns 0). Aggregates can't be used in WHERE, which runs before grouping; conditions on them go in HAVING.

In practice

SELECT country, count(*) FROM customers GROUP BY country returns one row per country with its number of customers.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.