Skip to main content
SQL • LESSON 11

HAVING

How do we filter groups based on aggregated results?

Intermediate2 Minutes190 XP
🤔 THE QUESTION

How do we filter groups based on aggregated results?

💡 WHAT IS IT?

HAVING filters groups created by GROUP BY, whereas WHERE filters individual rows before grouping.

🎯 WHAT IS IT USED FOR?

Finding large departments, high-volume sellers, stores exceeding revenue targets.

💻 EXAMPLE
SELECT department,
COUNT(*) AS employee_count
FROM employees
GROUP BY department
HAVING COUNT(*) > 5;

🎯 Mission Objectives

Practice typing production-grade SQL code for HAVING.

  • HAVING
  • GROUP BY
  • Aggregate filtering
  • Post-aggregation conditions