Kodewick
Start learning →
Basic←→0 / 70

Stock by category

#031BasicGROUP BYAggregates3 min

Month-end count at the shop: how many items are left in each category? Add up the stock of each category. Two columns: the category, and its total stock.

The tables
products
idnamecategorypricestock
1Milk teadrink1230
2Lemon waterdrink850
3Cheesecakecake256
4Cookiesnack580
5Browniecake180
6Iced coffeedrink1520
7Chipssnack740
8Fruit tartcake284
8 rows
query.sql
-- your code here: group by category, SUM(stock) adds up each group
SELECT category, stock
FROM products;
Ctrl + Enter runs too
Result

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