Skip to main content
SQL โ€ข LESSON 107

CTE Business Query

How can we identify departments with high total salary costs?

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

How can we identify departments with high total salary costs?

๐Ÿ’ก WHAT IS IT?

CTEs simplify enterprise business logic by separating cost aggregation from dimension lookups.

๐ŸŽฏ WHAT IS IT USED FOR?

Budget threshold audits, department expenditure analysis, enterprise financial reporting.

๐Ÿ’ป EXAMPLE
WITH department_cost AS (
    SELECT
        department_id,
        SUM(salary) AS total_salary
    FROM employees
    GROUP BY department_id
)
SELECT d.department_name, dc.total_salary
FROM department_cost dc
JOIN departments d
ON dc.department_id = d.department_id
WHERE dc.total_salary > 1000000;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for CTE Business Query.

  • โœ“ CTE business query
  • โœ“ Budget expenditure
  • โœ“ JOIN with threshold
  • โœ“ Financial reporting