The way the clerk walks
- O(log n) · Easy
- Free
- SQL
- sorting
- conditionals
Problem
The stock clerk walks the store the same way every time: in through aisle 1, which is Devices; on to aisle 2, Displays, and aisle 3, Audio; and out through aisle 4, Accessories, right by the register. The clerk wants the restocking list to follow that walk, but sorted by section it starts at the register.
Show two columns: the aisle number, and then the product's name. Sort the rows by aisle and, within each aisle, by name. Anything that comes in from a section that doesn't have an aisle yet goes in aisle 5, the one in the back.
What it has to return
These rows, in this order
| aisle | name |
|---|---|
| 1 | Laptop |
| 1 | Tablet |
| 2 | Monitor |
| 3 | Headphones |
| 3 | Speaker |
| 4 | Cable |
| 4 | Keyboard |
| 4 | Mouse |
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 category, name
FROM products
ORDER BY category, name;It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.