How can we identify departments with high total salary costs?
CTEs simplify enterprise business logic by separating cost aggregation from dimension lookups.
Budget threshold audits, department expenditure analysis, enterprise financial reporting.
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;Practice typing production-grade SQL code for CTE Business Query.