Skip to main content
SQL โ€ข LESSON 75

WHERE Before GROUP BY

How can we analyze active employees by department?

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

How can we analyze active employees by department?

๐Ÿ’ก WHAT IS IT?

WHERE filters individual rows before grouping, reducing the dataset before GROUP BY executes.

๐ŸŽฏ WHAT IS IT USED FOR?

Active-only headcount tracking, valid transaction summaries, active subscription counts.

๐Ÿ’ป EXAMPLE
SELECT department, COUNT(*) AS active_employees
FROM employees
WHERE status = 'Active'
GROUP BY department;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for WHERE Before GROUP BY.

  • โœ“ WHERE before GROUP BY
  • โœ“ Row pruning
  • โœ“ Status filtering
  • โœ“ Optimized grouping