Write a SQL query that shows, for each employee, their name,department, salary, and **what percentage of their department's
total salary budget they represent** — rounded to 1 decimal place.
Order the output by department, then by salary descending.
Table: `employees`
| id | name | department | salary |
|---|---|---|---|
| 1 | Alice | Engineering | 60000 |
| 2 | Bob | Engineering | 40000 |
| 3 | Dave | Marketing | 75000 |
| 4 | Eve | Marketing | 50000 |
| 5 | Frank | Marketing | 25000 |
Engineering total = 100 000 → Alice 60 %, Bob 40 %
Marketing total = 150 000 → Dave 50 %, Eve 33.3 %, Frank 16.7 %
Expected output (columns: name, department, salary, pct)
Alice|Engineering|60000|60.0
Bob|Engineering|40000|40.0
Dave|Marketing|75000|50.0
Eve|Marketing|50000|33.3
Frank|Marketing|25000|16.7Combine
SUM(salary) OVER (PARTITION BY department)with regulararithmetic — this is the pattern that separates intermediate from
advanced SQL practitioners.
Sample tests