Skip to main content
SQL • LESSON 10

GROUP BY

How can we aggregate metrics broken down by category or department?

Intermediate2 Minutes180 XP
🤔 THE QUESTION

How can we aggregate metrics broken down by category or department?

💡 WHAT IS IT?

GROUP BY partitions rows into groups having the same values in specified columns.

🎯 WHAT IS IT USED FOR?

Departmental headcount, sales by region, daily active users, orders by country.

💻 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
  • Categorical aggregation
  • COUNT(*)
  • Grouping columns