HardBusiness Analytics High Frequency
Emergency Department Conversion Funnel to Inpatient Admission
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
Analyze patient records in `er_patient_journey`.
Calculate:
1. `total_arrivals`: Count of all patient visits
2. `physician_examined`: Count where `examined_by_md = true`
3. `inpatient_admitted`: Count where `admitted_to_ward = true`
4. `admission_rate_pct`: Percentage of arrivals that converted to inpatient admission:
`ROUND(100.0 * COUNT(*) FILTER (WHERE admitted_to_ward = true) / COUNT(*), 1)`
Return in a single summary row.
Why Technical Interviewers Ask This
Hospital executive boards monitor emergency triage drop-off: how many presenting ER patients are triaged, examined by a physician, and ultimately admitted to inpatient hospital beds.
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 business analytics constructs.
Canonical Modern SQL Solution
PostgreSQL 16 / ANSI SQLSELECT
COUNT(*) AS total_arrivals,
COUNT(*) FILTER (WHERE examined_by_md = true) AS physician_examined,
COUNT(*) FILTER (WHERE admitted_to_ward = true) AS inpatient_admitted,
ROUND(100.0 * COUNT(*) FILTER (WHERE admitted_to_ward = true) / COUNT(*), 1) AS admission_rate_pct
FROM er_patient_journey;Approach Breakdown
This query addresses the problem requirements by filtering and structuring data in Business Analytics. It meets the target criteria: Conversion funnel counts and admission rate percentage from the emergency department.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 Business Analytics 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.