SolveWithSQL

SQL Beginner Challenge 25: Summing Values with SUM()

Difficulty: Beginner
Estimated time: 10–15 minutes
SQL concepts: SUM(), aggregation, numeric analysis
Goal: Calculate totals across multiple rows.

The Challenge

The product manager asks:

“What is the total value of all products?”

So far, you’ve learned how to:

  • Filter rows
  • Count records
  • Group data

Now it’s time to measure magnitude, not just quantity.

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 total price of all products

Expected Output

total_value
478.46

(Sum of all product prices)

Constraints

  • Use the SUM() function
  • Do not use SELECT *
  • Return a single numeric result

Hint (Optional)

Aggregation functions like SUM() work across multiple rows, returning one result.

SELECT
SUM(price) AS total_value
FROM products;

Explanation

  • SUM(price) adds together all values in the price column
  • The database returns a single row with the total

This pattern is fundamental for:

  • Revenue calculations
  • Financial reports
  • Inventory valuation
  • Business KPIs

Common Mistakes

  1. Using SUM on non-numeric columns
  2. Forgetting that SUM ignores NULL values
  3. Mixing SUM with non-aggregated columns without GROUP BY

Optional Extension (Mini Bonus)

Try answering these variations:

  1. What is the total value of products costing more than 50?
  2. What is the total value per category?
  3. What is the total value of Accessories only?

(You already know all the tools needed.)

Why this challenge matters

Counting tells you how many.
Summing tells you how much.

Once learners understand SUM(), SQL becomes a true analytics tool, not just a query language.

Next Challenge

Beginner Challenge #26: Calculating Averages with AVG()

🔗 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.