Provider Analytics Path · Mission 24 of 25Expert

Department scorecard

Use multiple CTEs to build a comprehensive multi-metric report

Back to Provider Analytics

The Brief

Michael TranCEOslack-dm

I need a department-level scorecard for the board. For each department, show: total encounters, average length of stay for inpatient discharges, average satisfaction score (exclude bad values), readmission rate, and complication rate. Combine the three ED name variants into one row. This is going to the board — it needs to be bulletproof.

You'll practice

Multiple CTEsComprehensive report

Tables & columns available

dim_departmentsdim6 columns
ColumnTypeKey
department_idINTPK
department_nameTEXT
department_typeTEXT
floorINT
bed_countINT
manager_nameTEXT
fact_encountersfact10 columns
ColumnTypeKey
encounter_idINTPK
patient_idINTFK → dim_patients
provider_idINTFK → dim_providers
department_idINTFK → dim_departments
admit_dateTEXT
discharge_dateTEXT
diagnosis_codeTEXT
diagnosis_descriptionTEXT
encounter_typeTEXT
discharge_dispositionTEXT
fact_quality_metricsfact7 columns
ColumnTypeKey
metric_idINTPK
encounter_idINTFK → fact_encounters
patient_idINTFK → dim_patients
metric_typeTEXT
metric_valueREAL
measurement_dateTEXT
reported_byTEXT

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

Build one CTE per metric (encounters, LOS, satisfaction, readmissions, complications). Every CTE needs a normalized department-name key so they all join on the same thing

Hint 2

Normalize the three ED name variants into one label inside each CTE. Then JOIN all the CTEs in the final SELECT on that label

Hint 3

`CASE WHEN department_name IN ('Emergency', ___, ___) THEN 'Emergency' ELSE ___ END AS dept_group` — every CTE exposes `dept_group`, and the final query joins on it