Difficulty: Beginner
Estimated time: 10–15 minutes
SQL concepts: AVG(), numeric aggregation, understanding averages
Goal: Calculate the average value across multiple rows.
The Challenge
The product manager asks:
“What is the average price of our products?”
Totals tell you how much.
Averages tell you what’s typical.
This is a very common business question used for pricing analysis, benchmarking, and reporting.
Database Table
products
| column_name | type | description |
|---|---|---|
| product_id | INTEGER | Unique product ID |
| name | TEXT | Product name |
| category | TEXT | Product category |
| price | DECIMAL | Product price |
Sample Data
| product_id | name | category | price |
|---|---|---|---|
| 101 | Wireless Mouse | Accessories | 24.99 |
| 102 | Mechanical Keyboard | Accessories | 89.00 |
| 103 | Monitor | Displays | 229.99 |
| 104 | USB-C Hub | Accessories | 34.50 |
| 105 | Laptop Stand | Workspace | 39.99 |
| 106 | Webcam | Accessories | 59.99 |
Your Task
Write a SQL query that returns:
- The average price of all products
Expected Output
| average_price |
|---|
| 79.74 |
(Average of all product prices)
Constraints
- Use the
AVG()function - Return a single numeric result
- Do not use
SELECT *
Hint (Optional)
Just like SUM(), AVG() works across multiple rows and returns one value.
SELECT
AVG(price) AS average_price
FROM products;
Explanation
AVG(price)calculates the mean value of thepricecolumn- The database adds all prices and divides by the number of rows
NULLvalues (if any) are ignored automatically
Averages are commonly used in:
- Pricing analysis
- Benchmarking
- Trend reports
- KPIs
Common Mistakes
- Averaging the wrong column
- Forgetting that AVG ignores NULL values
- Mixing AVG with non-aggregated columns without GROUP BY
Optional Extension (Mini Bonus)
Try answering these variations:
- What is the average price of products costing more than 50?
- What is the average price per category?
- What is the average price of Accessories only?
(You already know everything needed to solve these.)
Why this challenge matters
Averages help teams understand what’s normal, not just what’s extreme.
Once learners combine COUNT, SUM, and AVG, they can answer most basic analytical questions in SQL.
Next Challenge
Beginner Challenge #27: Finding Minimum and Maximum Values (MIN / MAX)
🔗 View reference solution on GitHub
(After you’ve tried the challenge)
Want more practical SQL challenges?
Subscribe to the Solve With SQL newsletter and get new problems delivered to your inbox.