0PricingLogin
SQL Academy · Lesson

COUNT, SUM, AVG, MIN, MAX

Use the five core aggregate functions, understand COUNT(*) vs COUNT(column), and know how NULLs are treated by each.

What Aggregates Do

An aggregate function collapses many rows into one value. Examples: total revenue, average rating, max date.

COUNT

Counts rows. Two flavours:

SELECT COUNT(*)         FROM users;          -- counts ALL rows
SELECT COUNT(email)     FROM users;          -- counts rows where email IS NOT NULL
SELECT COUNT(DISTINCT country) FROM users;   -- distinct non-NULL countries

All lessons in this course

  1. COUNT, SUM, AVG, MIN, MAX
  2. GROUP BY Single and Multiple Columns
  3. HAVING vs WHERE
  4. Common Pitfalls: NULLs in Aggregates
← Back to SQL Academy