EasyFundamentals
Emergency Room Urgent Triage Filtering
Frequently Asked By:AppleGoogleAmazon
Interactive In-Browser Workspace
Practice this problem on live schema tables in PostgreSQL 16 WASM with instant row verification and visual EXPLAIN plans.
Problem Statement
Query the `emergency_visits` table for patients who have status `'waiting'` and are classified under triage levels `'Resuscitation'` or `'Emergent'`.
Return the following columns:
1. `visit_id`
2. `patient_name`
3. `triage_level`
4. `vital_pulse`
5. `arrival_time`
Order results by `arrival_time` ascending so the earliest arrivals are attended to first.
Why Technical Interviewers Ask This
MetroHealth Hospital's emergency department is handling a surge of incoming patients. Charge nurses need an immediate list of patients classified under high-urgency triage levels ('Resuscitation' and 'Emergent') who are still awaiting clinical examination.
Common Pitfalls & Interview Traps
Forgetting required sorting and deterministic tie-breaking.
Not accounting for NULL or zero-value denominators during calculations.
Using inefficient quadratic subqueries instead of single-pass fundamentals constructs.
Canonical Modern SQL Solution
PostgreSQL 16 / ANSI SQLSELECT
visit_id,
patient_name,
triage_level,
vital_pulse,
arrival_time
FROM emergency_visits
WHERE status = 'waiting'
AND triage_level IN ('Resuscitation', 'Emergent')
ORDER BY arrival_time ASC;Approach Breakdown
This query addresses the problem requirements by filtering and structuring data in Fundamentals. It meets the target criteria: List of waiting emergency patients under Resuscitation or Emergent triage, sorted chronologically.Edge Cases to Verbally Clarify with Your Interviewer
The dataset contains zero matching records (must return valid empty result without crashing).
Multiple records tie on sorting criteria (must evaluate tie-breaking order deterministically).
Foreign keys or secondary attributes have NULL values.
Frequently Asked Follow-Up Questions
What makes this question a favorite among Apple and Google interviewers?
Interviewers use this problem to test whether candidates write defensive, scalable Fundamentals queries that run efficiently on multi-million row production databases without excessive memory usage.
How does the query optimizer execute this query?
Using single-pass table scans with index lookups or sort buffers. Running EXPLAIN (ANALYZE, BUFFERS) in the DB Exercises workbench visualizes the execution nodes and buffer hit cache.