Final project: a sales report for an online shop
Bring the whole SQL course together: answer seven real business questions about the sample shop with joins, grouping, LEFT JOIN and CASE, then write up your findings, with a rubric and worked solution.
🎯 By the end of this project you will be able to:
- Turn business questions into SQL queries
- Combine joins, filters, grouping, LEFT JOIN and CASE in one report
- Check results and explain them in plain English
Outline
- The brief
- Starter materials
- Milestones: the seven questions
- Question 1: Total revenue
- Question 2: Revenue by category
- Question 3: Top customers
- Question 4: Monthly trend
- Question 5: Customers to win back
- Question 6: Products that never sold
- Question 7: Cancellation rate
- Write the summary
- Recap
- Quiz
- Self-check and complete
The brief
The owner of the online shop has written to you:
Your deliverables:
- A file
sales_report.sqlwith one query for each of the seven questions below, each with a comment saying which question it answers. - A short written summary (4 to 6 sentences) with the key numbers and two recommendations, in plain English for someone who does not know SQL.
Starter materials
Use the same shop.db you have used throughout the course. If you changed or deleted data in lesson 12, reload shop.sql first so your numbers match the solution.
⬇ Download shop.sqlRun it again in the Execute SQL tab to reset the database to the starting data.
Create a new file called sales_report.sql in a text editor, or write your queries in DB Browser's Execute SQL tab and save the tab as a file.
Milestones: the seven questions
Work through the questions in order; each one builds on skills from the one before. For each, write the query, run it, and sanity-check the answer (does it add up? does it match what you saw in earlier lessons?). Open each worked solution only after you have tried it.
| # | Question | Skills |
|---|---|---|
| 1 | What is total revenue, and how many orders count towards it? | JOIN, WHERE, SUM, COUNT (lessons 6, 9) |
| 2 | What is revenue and units sold per category, highest revenue first? | JOIN, GROUP BY, ORDER BY (lessons 7, 9) |
| 3 | Who are the top 3 customers by revenue, and where are they? | Three-table JOIN, GROUP BY, LIMIT (lessons 4, 9) |
| 4 | What are orders and revenue per month? Is the shop growing? | substr, GROUP BY (lesson 7) |
| 5 | Which customers with an email have never ordered? | LEFT JOIN, IS NULL (lessons 5, 10) |
| 6 | Which products have never sold (ignoring cancelled orders)? | LEFT JOIN with a condition in ON (lesson 10) |
| 7 | What percentage of orders were cancelled? | CASE inside SUM (lesson 11) |
Question 1: Total revenue
Your turn
Total revenue and counted orders
Calculate total revenue and the number of orders that count towards it.
Show the solution
-- Q1: total revenue and number of orders that count
SELECT SUM(p.price * o.quantity) AS revenue,
COUNT(*) AS orders
FROM orders AS o
JOIN products AS p ON o.product_id = p.product_id
WHERE o.status <> 'cancelled';Result: 1 row
| revenue | orders |
|---|---|
| 7276 | 13 |
How to get there: The price lives in products, so join it in, then multiply by quantity for each order line and add them up. 15 orders minus 2 cancelled leaves 13. Check: in lesson 9 the customer totals were 1200 + 1200 + 1148 + 1109 + 900 + 690 + 630 + 399 = 7276.
Question 2: Revenue by category
Your turn
Revenue and units per category
Show each category's revenue and units sold, highest revenue first.
Show the solution
-- Q2: revenue and units sold per category
SELECT p.category,
SUM(p.price * o.quantity) AS revenue,
SUM(o.quantity) AS units
FROM orders AS o
JOIN products AS p ON o.product_id = p.product_id
WHERE o.status <> 'cancelled'
GROUP BY p.category
ORDER BY revenue DESC;Result: 4 rows
| category | revenue | units |
|---|---|---|
| Electronics | 2699 | 3 |
| Books | 2150 | 5 |
| Stationery | 1230 | 11 |
| Home | 1197 | 3 |
How to get there: The categories add up to 7276, matching question 1, which is a good check. Notice the contrast: Stationery sells the most units (11) but earns less than Electronics, which earns the most from only 3 units.
Question 3: Top customers
Your turn
Top 3 customers
List the top 3 customers by revenue with their country. Break ties by name.
Show the solution
-- Q3: top 3 customers by revenue
SELECT c.name, c.country,
SUM(p.price * o.quantity) AS spent
FROM orders AS o
JOIN customers AS c ON o.customer_id = c.customer_id
JOIN products AS p ON o.product_id = p.product_id
WHERE o.status <> 'cancelled'
GROUP BY c.customer_id, c.name, c.country
ORDER BY spent DESC, c.name
LIMIT 3;Result: 3 rows
| name | country | spent |
|---|---|---|
| Emma Brown | Australia | 1200 |
| Ravi Kumar | India | 1200 |
| John Smith | UK | 1148 |
How to get there: Emma and Ravi tie on 1200 (each bought a Desk Lamp), which is why the tie-breaker matters: without it, which one appears first could change. Ravi would be higher if his cancelled order counted.
Question 4: Monthly trend
Your turn
Orders and revenue per month
Show orders and revenue for each month, in date order.
Show the solution
-- Q4: orders and revenue per month
SELECT substr(o.order_date, 1, 7) AS month,
COUNT(*) AS orders,
SUM(p.price * o.quantity) AS revenue
FROM orders AS o
JOIN products AS p ON o.product_id = p.product_id
WHERE o.status <> 'cancelled'
GROUP BY month
ORDER BY month;Result: 2 rows
| month | orders | revenue |
|---|---|---|
| 2025-09 | 9 | 4529 |
| 2025-10 | 4 | 2747 |
How to get there: Revenue fell from 4529 in September to 2747 in October, about 39% lower, and orders fell from 9 to 4. Two months is too short to call a trend, but it is worth watching. (Some data is only up to 15 October, so check whether October is a full month before drawing conclusions. Asking “is the data complete?” is a key analyst habit.)
Question 5: Customers to win back
Your turn
Never-ordered customers with an email
List customers who have never placed an order and have an email address, with their join date.
Show the solution
-- Q5: customers to win back
SELECT c.name, c.email, c.joined_on
FROM customers AS c
LEFT JOIN orders AS o ON o.customer_id = c.customer_id
WHERE o.order_id IS NULL
AND c.email IS NOT NULL;Result: 1 row
| name | joined_on | |
|---|---|---|
| Kofi Mensah | kofi@example.com | 2025-09-14 |
How to get there: Two customers have never ordered (Sara and Kofi), but only Kofi can be emailed. This is the left join and IS NULL pattern from lesson 10.
Question 6: Products that never sold
Your turn
Products with no sales
List products that have never sold, ignoring cancelled orders.
Show the solution
-- Q6: products with no sales (cancelled orders do not count)
SELECT p.name, p.category, p.price
FROM products AS p
LEFT JOIN orders AS o
ON o.product_id = p.product_id
AND o.status <> 'cancelled'
WHERE o.order_id IS NULL
ORDER BY p.name;Result: 1 row
| name | category | price |
|---|---|---|
| Coffee Mug | Home | 249 |
How to get there: The status condition goes in ON, not WHERE, so a product whose only orders were cancelled would still count as unsold. Putting o.status <> 'cancelled' in WHERE would remove every unmatched row, because their status is NULL.
Question 7: Cancellation rate
Your turn
Cancellation rate
Show the total number of orders, the number cancelled, and the cancellation rate as a percentage with one decimal place.
Show the solution
-- Q7: cancellation rate
SELECT COUNT(*) AS orders,
SUM(CASE WHEN status = 'cancelled' THEN 1 ELSE 0 END) AS cancelled,
ROUND(100.0 * SUM(CASE WHEN status = 'cancelled' THEN 1 ELSE 0 END) / COUNT(*), 1) AS cancel_rate_pct
FROM orders;Result: 1 row
| orders | cancelled | cancel_rate_pct |
|---|---|---|
| 15 | 2 | 13.3 |
How to get there: 2 out of 15 is 13.3%. 100.0 (not 100) makes SQLite use decimal division; with whole numbers, 200 / 15 would give 13.
Write the summary
Now write 4 to 6 sentences for the shop owner. Lead with the most important number, use plain words, and end with recommendations. Compare yours with this model answer:
Recap
- You agreed a definition of revenue before querying, and used it consistently.
- You answered seven business questions with joins, grouping, LEFT JOIN, CASE and subtotals.
- You checked answers against each other (categories add up to the total).
- You explained the results in plain English with recommendations.
Check your understanding
Answer all 3 questions, then check your answers to see an explanation for each one.
1. Why should the status condition in question 6 go in the ON clause?
2. Category revenues add up to 7276, the same as total revenue. Why is that check useful?
3. What does `ROUND(100.0 * 2 / 15, 1)` return?
Self-check and complete the course
Tick every rubric item to complete the project.