Entry, mid, and high
- O(n log n) · Hard
- Full plan
- SQL
- grouping
- conditionals
- sorting
Problem
For the store's flyer, the owner splits the catalog into three price tiers: Entry if the product costs less than 50, Mid if it costs 50 or more but less than 200, and High from 200 on up.
Show the tier, then how many products it has, then how many units all of them have in stock put together. The flyer reads from cheap to pricey: the entry tier first, then the mid tier, and the high tier last.
What it has to return
These rows, in this order
| tier | how_many | units |
|---|---|---|
| Entry | 3 | 42 |
| Mid | 3 | 20 |
| High | 2 | 10 |
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, stock
FROM products
ORDER BY price;It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.