Skip to the content

The display case backup

Problem

The display case by the entrance holds the hook: the cheapest thing the store can sell today. The owner wants the backup on hand for the day that one runs out: the second-cheapest product among the ones in stock. Show its name and its price, in that order. It's a single row, and anything out of stock doesn't compete, however cheap it is.

What it has to return

These rows, in any order

nameprice
Keyboard45.5

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, price
FROM products
ORDER BY price
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 →