Trailing their own team
- O(n log n) · Hard
- Full plan
- SQL
- subqueries
- nulls
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
| name | salary |
|---|---|
| Rachel | 1900 |
| Nicole | 2100 |
| Samuel | 3000 |
| Lydia | 3000 |
| Frank | 2600 |
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;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.