Lesson 25 — Ultimate: sales report
Boss level: a real sales report
Time to combine everything: JOIN to get names, WHERE to drop cancelled orders, GROUP BY per product, aggregates for units and revenue, HAVING to hide tiny sellers, and ORDER BY + LIMIT for a top list. Build it clause by clause and run it after each step.
SELECT p.name, SUM(o.qty) AS units, SUM(o.qty * p.price) AS revenue
FROM orders o JOIN products p ON p.id = o.product_id
...
Why it matters: this is the kind of query a business owner actually asks for: "what are my best products this month?".
Write the missing WHERE, HAVING and ORDER BY lines (see the TODOs). Expected: Lamp first, then Mug.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based Databases & SQL courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for Databases & SQL books — check the publication year so the examples match current versions.
Search Amazon →