Skip to main content
SQL • LESSON 75

WHERE Before GROUP BY

How can we analyze active employees by department?

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