Chapter 8 · Window Functions
55. Highest and Lowest Paid Doctor per Department
Hard40 XPHealthcare
For each doctor, show their department name, salary, the name of the highest-paid doctor in their department (top_earner), and the name of the lowest-paid (lowest_earner). Use FIRST_VALUE and LAST_VALUE window functions. Order by department name, salary descending.
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.