Skip to the content

Entry, mid, and high

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

tierhow_manyunits
Entry342
Mid320
High210

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;
Solve this challenge

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.

More O(n log n) challenges

See all challenges →