Filtering Only What Matters
Pick exactly the rows you want—so surprise categories don't sneak in.
Why this matters
If your filter lists what to exclude, a new category can sneak in unnoticed. Naming what you want is safer.
A "Not This" List Misses Surprises
status != 'CANCELLED' still lets in REFUNDED and TEST orders. You cannot list every unwanted status.
In real life: If a bouncer says "anyone except people in red", someone in orange gets in. A new status you did not think of gets through in the same way.
Name What You Want
WHERE status = 'COMPLETED' keeps only finished orders. Any new status is left out automatically.
In real life: If the bouncer says "only people on the list", anyone new is turned away. Choosing COMPLETED works like that list.
GROUP BY Gives One Line Each
GROUP BY region gives one total for each region instead of one grand total.
In real life: A manager wants "sales by region", not one big number. GROUP BY region splits the total into one line for Lagos, one for Abuja, and so on.
Your practice task
Report total sales revenue for each region. Filter strictly for completed purchases (ignoring pending, refunded, or test transactions), and group your totals by region.
How to do it
- Look at all the status values in the data.
- Decide which single status counts as real sales.
- Filter on that status and get one total for each region.
- Press Run proof and read the checklist.
Practice it for free in the app. You get instant checks that show what you got right and what to fix. A lesson takes about two minutes and you can try as many times as you like.
Quick reference: Include-Only Filter
Name what you want to keep, rather than listing what to throw away.
More lessons in this course
- SQL LEFT JOIN Example: Keep Every CustomerJoin database tables without accidentally losing records or multiplying totals.
- Counting Unique RecordsCount unique individuals instead of duplicate transactions in summary reports.
- SQL HAVING vs WHERE Explained With ExamplesFilter raw records with WHERE and filter calculated totals with HAVING.