Kodewick
Start learning →
Basic←→0 / 70

Big categories

#035BasicGROUP BYAggregates4 min

The owner wants to put the biggest categories by the door. Group by category and count the items in each, keeping only the categories with more than 2. Two columns: the category, and how many items.

The tables
products
idnamecategorypricestock
1Milk teadrink1230
2Lemon waterdrink850
3Cheesecakecake256
4Cookiesnack580
5Browniecake180
6Iced coffeedrink1520
7Chipssnack740
8Fruit tartcake284
8 rows
query.sql
SELECT category, COUNT(*)
FROM products
GROUP BY category
-- your code here: HAVING keeps the groups whose COUNT(*) is more than 2
;
Ctrl + Enter runs too
Result

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