Chapter 8 · Window Functions
58. Each Doctor's Share of Department Salary Budget
Hard40 XPHealthcare
For each doctor, compute what percentage of their department's total salary they represent. Use a window function to compute the department total. Return department name, doctor full name, salary, dept_total_salary, and salary_share_pct (rounded to 1 decimal). Order by department name, salary_share_pct 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.