Module 3 · Lesson 3 of 411/57 in the course~14 min
Module lessons (3/4)
Grouping with GROUP BY
Lesson preview5 hands-on exercises readySQL Course · Module 3 — JOIN and GROUP BY
Compute one aggregate row per group, such as per department.
What you'll learn in this lesson
- Aggregate data by homogeneous groups with
GROUP BY(one resulting row for each distinct key). - Apply the iron rule of compatibility between
SELECTandGROUP BY. - Build multi-table reports and multi-key groupings by combining
JOIN,GROUP BYand aggregate functions.
Overview
While COUNT(*) without GROUP BY compresses the entire table into a single corporate figure, GROUP BY first partitions the rows into as many buckets as there are distinct keys and then applies the aggregates (COUNT, SUM, AVG) separately to each group.
Each expression that appears in the SELECT list when GROUP BY is present can only belong to one of two categories:
Sections covered in this lesson
- 11. Mental Model: The Golden Rule of GROUP BY
- 22. Progressive & Annotated Examples
- 33. Interactive Lab: Watch the Grouping Step by Step
- 44. Diagnostic Verification (Quiz)
- 55. Progressive Practical Laboratory
Pro Lesson · Module 3 — JOIN and GROUP BY
Unlock "Grouping with GROUP BY" and the full SQL Course curriculum
Compute one aggregate row per group, such as per department.
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.