Leveling Up: Aggregations in SQL
products
table and explore this step by step.
product_id | product_name | category | price | stock |
---|---|---|---|---|
1 | Wireless Mouse | Electronics | 1200 | 25 |
2 | Yoga Mat | Fitness | 800 | 50 |
3 | Bluetooth Speaker | Electronics | 2500 | 15 |
4 | Water Bottle | Fitness | 300 | 100 |
5 | Smartwatch | Electronics | 5000 | 10 |
total_products |
---|
5 |
total_stock |
---|
200 |
average_price |
---|
1960 |
highest_price | lowest_price |
---|---|
5000 | 300 |
category | total_products |
---|---|
Electronics | 3 |
Fitness | 2 |
category
and then counts the number of products in each group.
category | total_stock |
---|---|
Electronics | 50 |
Fitness | 150 |
stock
column for each category.
category | total_products |
---|---|
Electronics | 3 |
Fitness | 2 |
category | total_stock | average_price | total_products |
---|---|---|---|
Electronics | 50 | 2900 | 3 |
Fitness | 150 | 550 | 2 |
products
table for now. Next, we’ll dive into joins, where we connect multiple tables to unlock even richer insights. Keep experimenting, and SQL will become second nature!