0
← Exercises/
Window Functions•12 of 14
Window FunctionsAdvancedPRO

Emergency Department Wait Time Quartiles with NTILE(4)

Scenario

Hospital quality assurance audits emergency department throughput. Patients are bucketed into wait-time quartiles to measure clinical delay across triage shifts.

Task
For each emergency patient in `er_throughput`, assign a wait quartile from 1 to 4 based on `wait_minutes` ascending (Quartile 1 = shortest wait, Quartile 4 = longest wait). Return: 1. `patient_id` 2. `triage_acuity` 3. `wait_minutes` 4. `wait_quartile`: `NTILE(4) OVER (ORDER BY wait_minutes ASC)` Order results by `wait_minutes` ascending, then by `patient_id` ascending.
Expected Output Format

ER patients categorized into 4 wait time quartiles.

Input Tables & Sample Data0 tables
Loading database schema...
Need a hint?
query.sql|Local Sandbox
Loading SQL editor...
Click "Run" or press ⌘ + Enter to execute your query

About the “Emergency Department Wait Time Quartiles with NTILE(4)” SQL Problem

Business Scenario

Hospital quality assurance audits emergency department throughput. Patients are bucketed into wait-time quartiles to measure clinical delay across triage shifts.

Expected Output & Criteria

ER patients categorized into 4 wait time quartiles.

Database Table Schema (PostgreSQL DDL)

PostgreSQL 16 WASM

This challenge executes directly against the following relational schema in your browser:

CREATE TABLE er_throughput (
        patient_id INT PRIMARY KEY,
        triage_acuity VARCHAR(30) NOT NULL,
        wait_minutes INT NOT NULL
      );

Target SQL Clauses & Operators

NTILEOVERORDER BY

Want more Window Functions practice?

Explore the full syllabus of 14 exercises, syntax guides, and interview pitfalls.

View Window Functions Track→