Skip to the content

What's still out goes first

Problem

The library's front desk wants the list of loans the way it would be read out loud: on top, the books that are still out, starting with the one that's been out the longest. Below them, the ones that came back, from the latest return to the earliest. If two came back the same day, the one that went out earlier goes first.

Show member, borrowed, and the return date, in that order. Where there's no return date, it should say Still out. To the database, that label is one more piece of text in the column, and when text is sorted, a letter comes after any digit.

What it has to return

These rows, in this order

memberborrowedcame_back
Dylan2026-01-10Still out
Hannah2026-01-12Still out
Ann2026-01-13Still out
Luke2026-01-082026-01-15
Ann2026-01-102026-01-14
Ann2026-01-022026-01-09
Luke2026-01-032026-01-05
Brian2025-12-202026-01-04

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 member, borrowed, returned
FROM loans
ORDER BY returned DESC;
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 →