Chapter 9 · Interview Level
62. Department Performance Dashboard
Hard40 XPHealthcare
Create a department performance dashboard. For each department, show: department name, total number of unique patients seen, total visits, average days between a patient's first and last visit (rounded to 1 decimal, as avg_visit_span_days), and total revenue (rounded to 2 decimals). Only include departments that have had at least one visit. Order by total_revenue descending.
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
- 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.