
📎 This article includes 3 downloadable practice files ↓
SQL looks intimidating until you notice it is just Excel operations written as sentences. Every query below maps to something you already do with the mouse. You can run all of them in the SQL Playground — no installation needed.
In this article
- 1. Look at the data (Ctrl+Home)
- 2. Pick columns (hide columns)
- 3. Filter (AutoFilter)
- 4. Sort (Sort A→Z / Z→A)
- 5. Calculated column (a formula column)
- 6. Totals by group (pivot table)
- 7. Filter on a total (pivot + value filter)
- 8. VLOOKUP → JOIN
- 9. Remove duplicates
- 10. Top N (sort + keep first rows)
- The order SQL actually runs in
- Try it yourself: step by step
Our sample table sales has columns: id, rep, region, product, qty, price, sale_date.
1. Look at the data (Ctrl+Home)
SELECT * FROM sales LIMIT 10;
2. Pick columns (hide columns)
SELECT rep, product, qty FROM sales;
3. Filter (AutoFilter)
SELECT * FROM sales
WHERE region = 'North' AND qty >= 5;
4. Sort (Sort A→Z / Z→A)
SELECT * FROM sales ORDER BY qty DESC, rep ASC;
5. Calculated column (a formula column)
SELECT id, rep, qty * price AS amount FROM sales;
6. Totals by group (pivot table)
SELECT region, SUM(qty * price) AS revenue, COUNT(*) AS orders
FROM sales
GROUP BY region
ORDER BY revenue DESC;
7. Filter on a total (pivot + value filter)
SELECT rep, SUM(qty) AS units
FROM sales
GROUP BY rep
HAVING SUM(qty) > 40;
WHERE filters rows before grouping; HAVING filters the grouped results.
8. VLOOKUP → JOIN
SELECT s.id, s.region, r.manager
FROM sales s
LEFT JOIN regions r ON s.region = r.region;
LEFT JOIN keeps every sales row even when no manager is found — like XLOOKUP returning blank instead of #N/A.
9. Remove duplicates
SELECT DISTINCT region, product FROM sales;
10. Top N (sort + keep first rows)
SELECT rep, SUM(qty * price) AS revenue
FROM sales
GROUP BY rep
ORDER BY revenue DESC
LIMIT 3;
The order SQL actually runs in
You write SELECT … FROM … WHERE … GROUP BY … HAVING … ORDER BY, but the database processes it as FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY. That is why you cannot use a column alias from SELECT inside WHERE — it does not exist yet.
Try it yourself: step by step
- Easiest: open the SQL Playground — the same data is loaded, nothing to install.
- To practise on your own PC, download sales.csv, regions.csv and queries.sql.
- Install DB Browser for SQLite (free). Create a new database → File → Import → Table from CSV → sales.csv (tick “Column names in first line”). Repeat for regions.csv.
- Open the Execute SQL tab, paste a query from queries.sql and press Ctrl+Enter.
- Challenge: write a query for the total revenue per region per month. Hint:
substr(sale_date, 1, 7)gives “2025-03”.
📎 Practice files for this article
- 🧾Sample sales data (CSV)60 rows: invoice, date, region, rep, product, qty, price u2014 import into any database or Google Sheets.⬇ CSV · 3 KB
- 🧾Regions table (CSV)Use it to practise JOIN (the SQL version of VLOOKUP).⬇ CSV · 70 B
- 🗃️All 10 queries (.sql)Copy-ready queries matching each section of the article.⬇ SQL · 736 B
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.