Chapter 5 · JOINs
58. Number of Unique Patients per Doctor
Medium20 XPHealthcare
Hospital management wants to understand each doctor's patient load. For each doctor, return their full name (first_name || ' ' || last_name) as doctor_name, specialty, and the number of distinct patients they have seen as patient_count. Only include doctors who have seen at least one patient. Order by patient_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.