Products per category
Easy
Show each category, its number of products and its avg_price (2 decimals).
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
| category | products | avg_price |
|---|---|---|
| Books | 3 | 53.0 |
| Electronics | 5 | 155.0 |
| Furniture | 3 | 335.67 |
| Grocery | 2 | 22.0 |
| Stationery | 2 | 9.75 |
5 rows
Show a solution
SELECT category, COUNT(*) AS products, ROUND(AVG(price), 2) AS avg_price FROM products GROUP BY category;
SQL used
New to SQL? The free SQL course teaches everything these problems use, with a self-checking exercise in every lesson.