Chapter 6 · Subqueries
54. Visits with Above-Average Billing for Their Doctor
Hard40 XPHealthcare
Identify visits where the billing amount exceeded the average billing amount for that doctor. Return visit_id, doctor_id, amount, and the doctor's average billing as doctor_avg_amount (rounded to 2 decimals). Order by amount descending.
Tables
- PKidINT
- FKpatient_id→ patients.idINT
- FKdoctor_id→ doctors.idINT
- visit_dateTEXT
- diagnosisTEXT
- notesTEXT
- follow_up_dateTEXT
- statusTEXT
- 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.