Chapter 5 · JOINs
64. Patient Out-of-Pocket vs Insurance Coverage
Medium20 XPHealthcare
For each patient with insurance, calculate total billed, total covered by insurance, and total patient responsibility across all their visits. Return patient full name, provider_name, total_billed, total_covered, and total_out_of_pocket (all rounded to 2 decimals). Only include patients with at least one billing record. Order by total_out_of_pocket descending.
Tables
- PKidINT
- first_nameTEXT
- last_nameTEXT
- date_of_birthTEXT
- genderTEXT
- emailTEXT
- phoneTEXT
- blood_typeTEXT
- cityTEXT
- stateTEXT
- FKinsurance_id→ insurance.idINT
- created_atTIMESTAMP
- PKidINT
- FKpatient_id→ patients.idINT
- FKdoctor_id→ doctors.idINT
- visit_dateTEXT
- diagnosisTEXT
- notesTEXT
- follow_up_dateTEXT
- statusTEXT
- PKidINT
- provider_nameTEXT
- plan_typeTEXT
- coverage_amountREAL
- copayREAL
- deductibleREAL
- PKidINT
- FKvisit_id→ visits.idINT
- amountREAL
- insurance_coveredREAL
- patient_responsibilityREAL
- statusTEXT
- billed_atTEXT
- paid_atTEXT
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.