Practice Free
← Syllabus|
Medium

15. Emergency Room Average Door-to-Doctor Wait Times

MediumAggregationsPostgreSQL 16PRO
Table: er_patient_encounters
+--------------+------+
| Column Name  | Type |
+--------------+------+
| encounter_id | int  |
| acuity_level | int  |
| wait_minutes | int  |
+--------------+------+

encounter_id is the unique key for this table. Each row contains record details for this enterprise dataset.

Hospital clinical operations track Emergency Department triage wait times in minutes to ensure high-acuity patients are seen well within medical protocol thresholds.

Group records in `er_patient_encounters` by `acuity_level`. Calculate: 1. `acuity_level` 2. `total_patients`: Total patients in this acuity tier 3. `avg_wait_minutes`: Average `wait_minutes` rounded to 1 decimal place 4. `max_wait_minutes`: Maximum recorded `wait_minutes` Order results by `acuity_level` ascending.

Return the result table ordered as specified. The result format is in the following example.

Example 1:
Input:
Preparing sample rows...
Output:
Calculating benchmark target...
Explanation:

Average and maximum ER wait time by acuity tier.

Constraints:
  • Query must utilize clause(s): GROUP BYAVGROUNDORDER BY
  • Result order matters (tie-breakers and sort order must be strictly preserved).
  • Engine: PostgreSQL 16 standard syntax (in-browser WASM).
query.sql|PostgreSQL 16 WASM
Loading SQL editor...
You must run your code first

Write your SQL query in the editor and click Run or Submit to test against in-browser PostgreSQL 16 WASM.

About the “Emergency Room Average Door-to-Doctor Wait Times” SQL Problem

Business Scenario

Hospital clinical operations track Emergency Department triage wait times in minutes to ensure high-acuity patients are seen well within medical protocol thresholds.

Expected Output & Criteria

Average and maximum ER wait time by acuity tier.

Database Table Schema (PostgreSQL DDL)

PostgreSQL 16 WASM
CREATE TABLE er_patient_encounters (
        encounter_id INT PRIMARY KEY,
        acuity_level INT NOT NULL,
        wait_minutes INT NOT NULL
      );

Target SQL Clauses & Operators

GROUP BYAVGROUNDORDER BY

Want more Aggregations practice?

Explore the full syllabus of 16 exercises and syntax guides.

View Aggregations Track