Skip to the content

Room for one badge

Problem

On the store's website there's room for a single badge next to each product, but several products qualify for two. Here's what takes priority: if there are no units left, Sold out, and there's nothing more to say. If fewer than 6 are left, Few left, which is more urgent than any promotion. Otherwise, if it costs 100 or more, Free shipping.

Everything else gets Available.

Show each product's name and its badge, in that order.

What it has to return

These rows, in any order

namebadge
KeyboardAvailable
MouseAvailable
MonitorFew left
CableSold out
LaptopFew left
TabletFree shipping
HeadphonesAvailable
SpeakerSold out

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
FROM products
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 →