Chapter 9 · Interview Level
59. Pivot Visit Counts by Status per Doctor
Hard40 XPHealthcare
Create a pivot-style report showing each doctor's visit counts broken down by status. Return doctor full name, completed_count, scheduled_count, cancelled_count, and no_show_count. Use conditional aggregation (SUM + CASE). Order by completed_count 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
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.