Chapter 5 · JOINs
68. Average Prescriptions per Visit by Doctor
Medium20 XPHealthcare
Management wants to compare prescribing habits. For each doctor, calculate the average number of prescriptions per visit. Return the doctor's full name, total visits, total prescriptions, and the average prescriptions per visit (rounded to 2 decimals). Only include doctors who have at least one visit. Sort by average descending.
Tables
- PKidINT
- first_nameTEXT
- last_nameTEXT
- specialtyTEXT
- FKdepartment_id→ departments.idINT
- emailTEXT
- phoneTEXT
- hire_dateTEXT
- salaryREAL
- PKidINT
- FKpatient_id→ patients.idINT
- FKdoctor_id→ doctors.idINT
- visit_dateTEXT
- diagnosisTEXT
- notesTEXT
- follow_up_dateTEXT
- statusTEXT
- PKidINT
- FKvisit_id→ visits.idINT
- medicationTEXT
- dosageTEXT
- frequencyTEXT
- start_dateTEXT
- end_dateTEXT
- refillsINT
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.