Skip to the content

Trailing their own team

Problem

A manager earns a good deal more than the team, and that pulls up the average of the whole department. HR wants to see who that leaves behind: the people who earn less than the average of their own department, with their own salary counted in that average.

Show the name and the salary, in that order. Someone who earns exactly the average doesn't show up. Neither does someone with no department: there's nobody to compare them with.

What it has to return

These rows, in any order

namesalary
Rachel1900
Nicole2100
Samuel3000
Lydia3000
Frank2600

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 e.name, e.salary
FROM employees e
WHERE e.salary < 3000;
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 →