Chapter 8 · Window Functions
47. Rank Doctors by Salary Within Department
Hard40 XPHealthcare
Rank doctors by salary within each department. Return the department_id, first name, last name, salary, and the rank (1 = highest salary). Use RANK().
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.