Provider Analytics Path · Mission 17 of 25Hard

ED wait times by day of week

Use EXTRACT(DOW), AVG with filtering, and a window function for baseline comparison

Back to Provider Analytics

The Brief

James HartwellVP of Operationsslack-dm

avg ED wait time by day of week. exclude the bad data over 480 min. also show an overall average across all days as a baseline column so i can see which days are above/below average. weekends are killing us — need proof.

You'll practice

EXTRACT(DOW)AVG() OVER()

Tables & columns available

fact_quality_metricsfact7 columns
ColumnTypeKey
metric_idINTPK
encounter_idINTFK → fact_encounters
patient_idINTFK → dim_patients
metric_typeTEXT
metric_valueREAL
measurement_dateTEXT
reported_byTEXT
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
dim_departmentsdim6 columns
ColumnTypeKey
department_idINTPK
department_nameTEXT
department_typeTEXT
floorINT
bed_countINT
manager_nameTEXT

Hints (3)

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

Hint 1

Two data quality issues compound: the three ED name variants AND the impossible wait times over 480. Filter both before you aggregate

Hint 2

Group by day-of-week with `EXTRACT`, and add a window function with no partition to put the grand average on every row

Hint 3

`SELECT EXTRACT(___ FROM measurement_date::date) AS day_of_week, AVG(metric_value) AS avg_wait, AVG(AVG(metric_value)) OVER () AS overall_avg ... WHERE metric_value <= ___ AND department_name IN (___, ___, ___) GROUP BY ___`