Loose ends
- O(n log n) · Hard
- Full plan
- SQL
- sets
- subqueries
- nulls
Problem
Before the audit, HR goes over the org chart and wants a single list of everything that doesn't add up, each item with its label. A department where nobody works gets no people. A department where someone works, but nobody with the role Manager, gets no manager. And a person who doesn't belong to any department gets no department.
Show the name, whether it's a department's or a person's, and its label, in that order. An empty department isn't missing a manager, it's missing everything: it shows up once, as no people.
What it has to return
These rows, in any order
| name | label |
|---|---|
| Legal | no people |
| Design | no manager |
| Carol | no department |
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,
'no people' AS label
FROM departments d
JOIN employees e
ON e.dept_id = d.id;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.