Use WHERE to filter by metric type and calculate aggregate statistics
Hi! I just got off a call with a patient family who waited 4 hours in the ED last Tuesday. Can you pull the average, minimum, and maximum ED wait times from our quality metrics? I want to bring data to the nursing leadership meeting tomorrow, not just anecdotes.
| Column | Type | Key |
|---|---|---|
| metric_id | INT | PK |
| encounter_id | INT | FK → fact_encounters |
| patient_id | INT | FK → dim_patients |
| metric_type | TEXT | |
| metric_value | REAL | |
| measurement_date | TEXT | |
| reported_by | TEXT |
Each hint you reveal reduces the XP you can earn. Try the query first.
Single-row summary with three aggregates side-by-side, scoped by a metric-type filter.
AVG, MIN, and MAX of the metric value, all in one SELECT. Filter the metric type in WHERE; no GROUP BY.
The metric table mixes wait times with other metric types — without the metric_type filter your stats average across unrelated metrics.