Loading the editor…
Sum billed and paid claim amounts for each department.
Revenue cycle compares what each department billed with what payers have paid. A claim that has not been priced yet contributes zero paid dollars, not a missing department.
Return department, billed_cents, and paid_cents. Sum billed_cents and treat a null paid_cents as zero. Sort by paid_cents descending, then department.
| 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: Categories with a high average line total
Related: Claims with patient names, Claim denial rate by department