sqlbeginner10 minutes
SQL Beginner Challenge: Calculate Total Sales per Customer
Practice basic SQL aggregation by calculating the total sales amount for each customer in a sales database.
Challenge prompt
Given a Sales table with columns CustomerID, ProductID, Quantity, and Price, write an SQL query to find the total sales amount per customer. The total sales amount is calculated by multiplying Quantity by Price for each row, summed up for each customer.
Guidance
- • Use the SUM() aggregate function to calculate the total sales for each customer.
- • Group the results by CustomerID to get totals per customer.
Hints
- • Remember to multiply Quantity by Price before summing.
- • Use GROUP BY clause for aggregation per customer.
Starter code
SELECT CustomerID,
-- Calculate total sales amount here
FROM Sales
GROUP BY CustomerID;Expected output
CustomerID | TotalSales ----------------------- 1 | 150.00 2 | 230.50 3 | 75.25
Core concepts
SQL AggregationGROUP BY clauseBasic SQL functions
Challenge a Friend
Send this duel to someone else and see if they can solve it.