Skip to main content
Albero Academy

Aggregate Functions

Summarise many rows into one value — COUNT, SUM, AVG, MIN, MAX.

Core Queries8 min

Aggregate functions collapse many rows into a single summary value. They answer "how many?", "what's the total?", "what's the average?" — the questions businesses ask constantly.

The five you need

summarise a column
SELECT
COUNT(*) AS n_students, -- number of rows
COUNT(email) AS n_with_email, -- non-NULL emails
AVG(package) AS avg_package,
MAX(package) AS top_package,
MIN(package) AS lowest,
SUM(package) AS total
FROM students;

Key takeaways

  1. 01Aggregate functions collapse many rows into one summary value.
  2. 02COUNT, SUM, AVG, MIN, MAX are the core five.
  3. 03COUNT(*) counts rows; COUNT(col) counts non-NULL values.
  4. 04Aggregates ignore NULLs (except COUNT(*)).

Finished this chapter?

Mark it complete to track your progress through SQL.