Skip to the content

Who signs off on my day off?

Problem

At this company, a day off is signed by the direct boss of whoever asks for it. Carol runs the company and has nobody above her: she signs her own.

HR wants the table that will go on the form. Show each person's name and the employee number (the id) of whoever signs for them, in that order. No cell is left empty.

Sort the rows by the signer's number, so each boss sees their people together, and within each boss, by name.

What it has to return

These rows, in this order

namesigned_by
Carol1
Grace1
Mark1
Paige1
Nicole2
Rachel2
Frank3
Lydia3
Samuel3

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 name, boss_id
FROM employees
ORDER BY boss_id, name;
Solve this challenge

It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.

More O(log n) challenges

See all challenges →