Skip to main content
Module 2 · Lesson 4 of 48/57 in the course~12 min
Module lessons (4/4)

Counting and Summarizing: COUNT, AVG, MAX

Lesson preview5 hands-on exercises readySQL Course · Module 2 — More Powerful SELECT

Aggregate functions: collapsing many rows into summary metrics.

What you'll learn in this lesson

  • Compute summary statistics on the entire table (or a subset filtered by WHERE) with COUNT, SUM, AVG, MIN, MAX.
  • Strictly distinguish between COUNT(*), COUNT(colonna) and COUNT(DISTINCT colonna) in the presence of NULL.
  • Avoid the mistake of mixing non-aggregated columns and aggregate functions without GROUP BY.

Overview

Until now, each query returned a maximum of one row per record read. Aggregation functions collapse many rows into a single summary value: counts, sums, averages, maximums, and minimums.

Visually verify that WHERE deletes rows before grouping and calculating AVG / COUNT, while filtering on already aggregated results occurs after with HAVING:

Sections covered in this lesson

  1. 11. Mental Model: How NULL Aggregates Manage
  2. 22. Progressive & Annotated Examples
  3. 33. Interactive Laboratory: WHERE Before Aggregation
  4. 44. Diagnostic Verification (Quiz)
  5. 55. Progressive Practical Laboratory
Pro Lesson · Module 2 — More Powerful SELECT

Unlock "Counting and Summarizing: COUNT, AVG, MAX" and the full SQL Course curriculum

Aggregate functions: collapsing many rows into summary metrics.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in SQL Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.