Skip to the content

What the team makes

Problem

Anyone applying for a job asks what people make in that department, and they aren't asking about the manager's paycheck. HR wants the number on hand: each department's average monthly salary, leaving out whoever has the role Manager.

Show the department's name, how many people go into the calculation, and their average salary, rounded to 2 decimals, in that order. Where there's no manager, everyone in the department counts. And where only the manager is left, or nobody works there, there's no team to average: that department isn't on the list.

What it has to return

These rows, in any order

namepeopleaverage
Sales22000
Tech32866.67
Design12400

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 d.name, e.role,
  e.salary
FROM employees e
JOIN departments d
  ON e.dept_id = d.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) challenges

See all challenges →