Skip to the content

Who's the boss around here?

Problem

At this company, being a boss isn't a role: a boss is anyone who has someone reporting to them. HR wants to know how many people each boss has and what those people's salaries add up to.

Show the name of each person with someone reporting to them, how many people report to them directly, and the sum of those people's salaries, in that order.

Sort from the highest sum to the lowest; on a tie, by name.

What it has to return

These rows, in this order

namepeoplepayroll
Carol310300
Paige38600
Mark24000

This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.

You start with this

SQL

SELECT b.name
FROM employees e
JOIN employees b
  ON e.boss_id = b.id
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n log n) challenges

See all challenges →