Products by price band
Medium
Count products per band: 'budget' (under 50), 'mid' (50 to under 300) and 'premium' (300 and over), with the count in products.
Tables: customers(customer_id, name, city, country, joined) · products(product_id, name, category, price) · orders(order_id, customer_id, order_date, status) · order_items(order_id, product_id, quantity, unit_price)
Your query✔ Solved
Show the expected result
| band | products |
|---|---|
| budget | 8 |
| mid | 4 |
| premium | 3 |
3 rows
Show a solution
SELECT CASE WHEN price < 50 THEN 'budget' WHEN price < 300 THEN 'mid' ELSE 'premium' END AS band, COUNT(*) AS products FROM products GROUP BY band;
SQL used
New to SQL? The free SQL course teaches everything these problems use, with a self-checking exercise in every lesson.