Nishaglobal Education logo

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.

Final projectAbout 2 hoursQuiz: 3 questions

🎯 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
  1. The brief
  2. Starter materials
  3. Milestones: the seven questions
  4. Question 1: Total revenue
  5. Question 2: Revenue by category
  6. Question 3: Top customers
  7. Question 4: Monthly trend
  8. Question 5: Customers to win back
  9. Question 6: Products that never sold
  10. Question 7: Cancellation rate
  11. Write the summary
  12. Recap
  13. Quiz
  14. Self-check and complete

The brief

The owner of the online shop has written to you:

Your deliverables:

  1. A file sales_report.sql with one query for each of the seven questions below, each with a comment saying which question it answers.
  2. 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.

#QuestionSkills
1What is total revenue, and how many orders count towards it?JOIN, WHERE, SUM, COUNT (lessons 6, 9)
2What is revenue and units sold per category, highest revenue first?JOIN, GROUP BY, ORDER BY (lessons 7, 9)
3Who are the top 3 customers by revenue, and where are they?Three-table JOIN, GROUP BY, LIMIT (lessons 4, 9)
4What are orders and revenue per month? Is the shop growing?substr, GROUP BY (lesson 7)
5Which customers with an email have never ordered?LEFT JOIN, IS NULL (lessons 5, 10)
6Which products have never sold (ignoring cancelled orders)?LEFT JOIN with a condition in ON (lesson 10)
7What 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
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

Query result
revenueorders
727613

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

Query result
categoryrevenueunits
Electronics26993
Books21505
Stationery123011
Home11973

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

Query result
namecountryspent
Emma BrownAustralia1200
Ravi KumarIndia1200
John SmithUK1148

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

Query result
monthordersrevenue
2025-0994529
2025-1042747

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

Query result
nameemailjoined_on
Kofi Mensahkofi@example.com2025-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
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

Query result
namecategoryprice
Coffee MugHome249

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

Query result
orderscancelledcancel_rate_pct
15213.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. 1. Why should the status condition in question 6 go in the ON clause?

  2. 2. Category revenues add up to 7276, the same as total revenue. Why is that check useful?

  3. 3. What does `ROUND(100.0 * 2 / 15, 1)` return?

Answer all 3 questions to check.

Self-check and complete the course

Self-check rubric

Tick each item only when your own project meets it.

Tick every rubric item to complete the project.