Skip to main content
SQL โ€ข LESSON 105

CTE Filtering

How can we calculate department averages and then filter them?

Advancedโฑ 3 Minutesโญ 1180 XP
๐Ÿค” THE QUESTION

How can we calculate department averages and then filter them?

๐Ÿ’ก WHAT IS IT?

Filtering a CTE in the final SELECT query simplifies post-aggregation analysis without complex HAVING clauses.

๐ŸŽฏ WHAT IS IT USED FOR?

High-paying department discovery, anomaly detection, threshold filtering on staged metrics.

๐Ÿ’ป EXAMPLE
WITH department_salary AS (
    SELECT department_id, AVG(salary) AS average_salary
    FROM employees
    GROUP BY department_id
)
SELECT *
FROM department_salary
WHERE average_salary > 90000;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for CTE Filtering.

  • โœ“ CTE filtering
  • โœ“ WHERE on CTE output
  • โœ“ Simplified thresholding
  • โœ“ Clean analytical queries