1. Bill lines with amounts
The shopkeeper, Meena ji, asks: “How much money did each bill line bring?” The sales table has qty but no price; products has the price. JOIN them, then multiply:
s.qty * p.price AS amount
This is the building block of every sales report: join the facts (sales) with the details (products), then calculate.
SELECT s.id, p.name, s.qty
FROM sales s
JOIN products p
ON p.id = s.product_id;
Challenge: Bill lines with ₹ amounts
Join sales with products. Show day, the product name, qty, price and qty * price named amount, for every sale, sorted by the sale’s id. Columns in this order: day, name, qty, price, amount.
2. The October report
Now the big one. Meena ji’s question: “In October, which categories earned at least ₹400, and which earned the most?”
This needs everything you learned, in this order:
JOIN sales with products (to get price and category)WHERE — only October: days look like 2026-10-05, so s.day LIKE '2026-10-%' (two sales are from September!)GROUP BY p.categorySUM(s.qty * p.price) AS revenueHAVING revenue of at least 400ORDER BY revenue DESC
Write it step by step and press Run after each step to see the result grow. This is exactly the kind of query data analysts write every day.
Challenge: Kirana shop monthly report
Write one query with two columns, category and revenue (SUM(qty * price)), for sales in October 2026 only (day LIKE '2026-10-%'). Keep only categories with revenue of at least 400, sorted by revenue highest first. It must use JOIN, GROUP BY and HAVING.