Kodewick
Start learning →
Mini challenge←→0 / 70

Running low

#067Mini challengeGROUP BYCASE6 min

The shop wants to know which category needs restocking. Group by category and count how many products in each have stock below 10 (0 if none). Pick category and that count; every category should be listed.

The tables
products
idnamecategorypricestock
1Milk teadrink1230
2Lemon waterdrink850
3Cheesecakecake256
4Cookiesnack580
5Browniecake180
6Iced coffeedrink1520
7Chipssnack740
8Fruit tartcake284
8 rows
query.sql
SELECT category,
  -- your code here: a SUM(CASE …) giving 1 when stock < 10 and 0 otherwise
FROM products
GROUP BY category;
Ctrl + Enter runs too
Result

Run shows what your query gives. When it looks right, Submit.