SQL LESSON 32 OF 32

Capstone: a business-ready report

Start with a business question, define the row grain, join carefully and validate totals. Report only paid orders to avoid mixing pending or cancelled sales. SQL skills grow through checking assumptions as much as writing queries.

हिन्दी में समझें

पहले व्यावसायिक सवाल और पंक्ति का अर्थ तय करें। सावधानी से जॉइन और रकम जाँचें। बिक्री में केवल paid orders लें। धारणाएँ जाँचना भी SQL कौशल है।

अभ्यास: products, order_items, orders से category और paid revenue निकालें। category से समूह; revenue घटता, फिर category क्रम।

Hinglish mein samjhein

Pehle business question aur row grain define karo. Joins carefully karo aur totals validate karo. Sales mein sirf paid orders lo. Assumptions check karna bhi SQL skill hai.

Practice: products,order_items,orders se category aur paid revenue; category group, revenue DESC phir category sorted.

A small SQL example

SELECT c.name,SUM(i.quantity*p.price) AS revenue FROM customers c JOIN orders o ON o.customer_id=c.id JOIN order_items i ON i.order_id=o.id JOIN products p ON p.id=i.product_id WHERE o.status='paid' GROUP BY c.id,c.name ORDER BY revenue DESC,c.id;

Examples use the fictional shop database bundled with the SQL playground: customers, products, orders, order_items and employees. The engine is SQLite; other SQL dialects may differ.

Try this example in the SQL playground →

Practise this idea

Return category and paid revenue using products, order_items and orders. Group by category; sort revenue descending, then category.

Check answer & explanation
SELECT p.category,SUM(i.quantity*p.price) AS revenue FROM products p JOIN order_items i ON p.id=i.product_id JOIN orders o ON o.id=i.order_id WHERE o.status='paid' GROUP BY p.category ORDER BY revenue DESC,p.category;

Join product and order facts through order_items. Filter paid orders before summing line values, then group by category to avoid mixing pending or cancelled revenue.

Stuck in the course? Choose Check answer for either the challenge or quiz. Read the explanation and continue to the next lesson at your own pace.

Check your understanding

Before trusting a report, check…

  1. Grain, joins and totals
  2. Only its colors
  3. Just the first row
Check the quiz answer

Grain, joins and totals

Start with a business question, define the row grain, join carefully and validate totals. Report only paid orders to avoid mixing pending or cancelled sales. SQL skills grow through checking assumptions as much as writing queries.

References & corrections

Use the official SQLite documentation for full language rules. Read how these lessons are made and checked. Found a mistake? Report it to Excel Keys with this lesson URL and a reproducible example.

FROM LEARNING TO BUSINESS RESULTS

Need a dashboard for your team?

Excel Keys designs custom Excel and HTML dashboards around your own KPIs and Excel files. They run offline in the browser, so your data stays on your computer.