Chapter 6 · Subqueries
38. Doctors Earning Above Department Average
Medium20 XPHealthcare
HR wants to identify high earners relative to their peers. Find doctors whose salary is above the average salary of their department. Return doctor full name, department_id, salary, and the department average salary (rounded to 2 decimals) as dept_avg_salary. Order by salary descending.
Tables
- PKidINT
- first_nameTEXT
- last_nameTEXT
- specialtyTEXT
- FKdepartment_id→ departments.idINT
- emailTEXT
- phoneTEXT
- hire_dateTEXT
- salaryREAL
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.