How can we calculate employee counts and then attach department names?
CTEs can be joined to physical dimension tables just like standard database tables.
Combining pre-aggregated metrics with dimension metadata, clean multi-step joins.
WITH department_counts AS (
SELECT department_id, COUNT(*) AS employee_count
FROM employees
GROUP BY department_id
)
SELECT d.department_name, dc.employee_count
FROM department_counts dc
JOIN departments d
ON dc.department_id = d.department_id;Practice typing production-grade SQL code for CTE with JOIN.