This free example uses six fictional sales in euros. Each row is a completed sale; cancellations, refunds and taxes are outside its scope. It introduces the method used in the guided project, which has its own dataset.
1. Understand the data before the query
sale_id identifies a sale; city gives its location; channel distinguishes store from online sales; amount is the value in euros. A unique identifier lets you check that no sale is counted twice.
| sale_id | city | channel | amount |
|---|---|---|---|
| 1 | Paris | store | 120 |
| 2 | Lyon | online | 80 |
| 3 | Paris | online | 180 |
| 4 | Lille | store | 50 |
| 5 | Lyon | store | 100 |
| 6 | Lille | online | 70 |
2. Turn the question into steps
- Start from sales: each row represents a sale.
- Group by city to get one row per city.
- Add amount with SUM to calculate revenue.
- Sort from the highest revenue to the lowest.
3. Run your first SQL analysis
Dialect: PostgreSQL. SELECT, SUM, GROUP BY and ORDER BY are widely shared across SQL engines.
SELECT city, SUM(amount) AS revenue
FROM sales
GROUP BY city
ORDER BY revenue DESC, city;Browser-based SQL environment
3. Run your first SQL analysis
Run a read-only query on this exercise's fictional data. Nothing is sent to SQL.tn.
4. Check the result before drawing conclusions
Paris totals €300, Lyon €180 and Lille €120. Together they make €600, matching the six sales. Each city has two sales: COUNT(*) would measure their number, not revenue.
5. Extend your analysis
Keep only the online channel. Place the filter before GROUP BY. The total should become €330: Paris €180, Lyon €80 and Lille €70. Explain how your scope changed.
A hint
Add WHERE channel = 'online' between FROM sales and GROUP BY city.
Continue in the guided project
You have practised reading, grouping and checking a result. Create a free account to work through the sales project missions and save progress. This sample does not automatically complete any project mission.