Skip to main content
SQL โ€ข LESSON 10

GROUP BY

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

Intermediateโฑ 2 Minutesโญ 180 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