Chapter 9 · Interview Level
57. Comprehensive Doctor Scorecard
Hard40 XPHealthcare
Build a doctor scorecard that shows: department name, doctor full name, total visits, total prescriptions written, total billing generated, and their rank by total billing within their department. Use CTEs for clarity. Only include doctors with at least 1 visit.
Tables
- PKidINT
- first_nameTEXT
- last_nameTEXT
- specialtyTEXT
- FKdepartment_id→ departments.idINT
- emailTEXT
- phoneTEXT
- hire_dateTEXT
- salaryREAL
- PKidINT
- nameTEXT
- floorINT
- FKhead_doctor_id→ doctors.idINT
- budgetREAL
- 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
- 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.