SolveWithSQL

SQL Beginner Challenge 26: Calculating Averages with AVG()

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_nametypedescription
product_idINTEGERUnique product ID
nameTEXTProduct name
categoryTEXTProduct category
priceDECIMALProduct price

Sample Data

product_idnamecategoryprice
101Wireless MouseAccessories24.99
102Mechanical KeyboardAccessories89.00
103MonitorDisplays229.99
104USB-C HubAccessories34.50
105Laptop StandWorkspace39.99
106WebcamAccessories59.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 the price column
  • The database adds all prices and divides by the number of rows
  • NULL values (if any) are ignored automatically

Averages are commonly used in:

  • Pricing analysis
  • Benchmarking
  • Trend reports
  • KPIs

Common Mistakes

  1. Averaging the wrong column
  2. Forgetting that AVG ignores NULL values
  3. Mixing AVG with non-aggregated columns without GROUP BY

Optional Extension (Mini Bonus)

Try answering these variations:

  1. What is the average price of products costing more than 50?
  2. What is the average price per category?
  3. 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.