Loading the editor…
Find visits that have started and do not have an end date.
Bed management treats a missing end date as a visit that is still open. A completed visit always has ended_on filled in.
Return id, patient_id, department, and started_on for encounters where ended_on is NULL. Sort by started_on, then id.
| id | name | birth_date | sex | city |
|---|---|---|---|---|
| 1 | Amina Yusuf | 1984-04-12 | F | Lagos |
| 2 | Hugo Berger | 1972-11-03 | M | Berlin |
| 3 | Mei Lin | 1990-06-21 | f | Shanghai |
| id | patient_id | department | started_on | ended_on | visit_type |
|---|---|---|---|---|---|
| 1 | 1 | Cardiology | 2025-01-06 | 2025-01-06 | outpatient |
| 2 | 1 | Cardiology | 2025-03-02 | 2025-03-04 | inpatient |
| 3 | 2 | Orthopedics | 2025-01-11 | 2025-01-11 | outpatient |
| id | encounter_id | code | description |
|---|---|---|---|
| 1 | 1 | I10 | Essential hypertension |
| 2 | 2 | I21.9 | Acute myocardial infarction |
| 3 | 3 | M17.1 | Knee osteoarthritis |
| id | encounter_id | billed_cents | paid_cents | status | submitted_on |
|---|---|---|---|---|---|
| 1 | 1 | 18000 | 15000 | paid | 2025-01-07 |
| 2 | 2 | 240000 | 198000 | paid | 2025-03-06 |
| 3 | 3 | 22000 | 0 | denied | 2025-01-12 |
Ctrl or Cmd + Enter runs the query. The database resets on every run.
Run the query to see rows from the sample database.
Next exercise: Customers without a completed order
Related: Outpatient visits in 2025, Normalize patient sex codes