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_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 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 thepricecolumn- The database returns a single row with the total
This pattern is fundamental for:
- Revenue calculations
- Financial reports
- Inventory valuation
- Business KPIs
Common Mistakes
- Using SUM on non-numeric columns
- Forgetting that SUM ignores NULL values
- Mixing SUM with non-aggregated columns without GROUP BY
Optional Extension (Mini Bonus)
Try answering these variations:
- What is the total value of products costing more than 50?
- What is the total value per category?
- 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.