All problems

Highest Budget-per-Employee Department

hardSQLJoinsSubqueries

Kestrel Labs is planning next year's headcount, and the CFO has a complaint about the current planning sheet: it lines the teams up by budget, and on that measure Engineering wins every single year. Engineering is also the biggest team. What she wants instead is the department with the most money standing behind each person on it — the one with room to hire well, rather than just room to hire.

The awkward part is that nothing in the schema records how big a team is. departments holds the money and nothing else; team size exists only as the number of employee rows pointing back at that department.

departments

id name budget
1 Engineering 900000
2 Sales 400000
3 Marketing 250000
4 Data 500000

employees — one row per person; department_id points at departments.id.

id name department_id salary hire_date manager_id
1 Ava Chen 1 145000 2021-03-14 NULL
2 Ben Ortiz 1 118000 2022-06-01 1
3 Cara Novak 1 121000 2023-01-10 1
4 Deshawn Lee 2 95000 2020-09-23 NULL
5 Elin Kask 2 88000 2022-11-05 4
6 Farid Amiri 3 76000 2023-04-18 NULL
7 Grace Kim 4 132000 2021-07-30 NULL
8 Hugo Silva 4 110000 2023-02-14 7
9 Ines Duarte 4 104000 2023-08-01 7
10 Jonas Weber 2 91000 2021-12-19 4

The tables are already created and filled in the editor — there is nothing to read from input.

Task: Write a query that returns a single row — name and budget_per_employee — for the department with the highest budget divided by its headcount, rounded to 2 decimals. Watch the arithmetic: budget and headcount are both stored as whole numbers. A department with nobody on it has no meaningful figure and should not appear.

Example output — shape only, on an invented team and figure.

name budget_per_employee
Facilities 212333.33

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…