Chapter 6 · Subqueries
42. Departments with Above-Average Doctor Count
Medium20 XPHealthcare
Show how many doctors each department has. Return department name, doctor_count, and the department's budget. Only include departments with at least 5 doctors. Order by doctor_count descending, then by department name.
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
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.