Skip to main content
SQL • LESSON 69

GROUP BY

How can we count employees in each department?

Intermediate3 Minutes820 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