Skip to the content

Loose ends

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

namelabel
Legalno people
Designno manager
Carolno 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;
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 →