Skip to main content
SQL โ€ข LESSON 69

GROUP BY

How can we count employees in each department?

Intermediateโฑ 3 Minutesโญ 820 XP
๐Ÿค” THE QUESTION

How can we count employees in each department?

๐Ÿ’ก WHAT IS IT?

GROUP BY collapses rows with identical column values into summary rows.

๐ŸŽฏ WHAT IS IT USED FOR?

Department headcounts, order counts by status, regional customer breakdowns.

๐Ÿ’ป EXAMPLE
SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for GROUP BY.

  • โœ“ GROUP BY clause
  • โœ“ Categorical grouping
  • โœ“ Row aggregation
  • โœ“ Headcount metrics