Before you start
You need Workbench and a running SQL engine. Every example includes its own input rows. No catalog, files, credentials, or external data is needed. These queries create no stored tables. Copy the SQL into Workbench and run the statements in order. Compare the result with the table below the query.WITH names input data for one statement only. Each example can run on its own.
1. Build a sales report
What are order count and sales for each region?
The report combines grouping, two measures, and result ordering.
Change one thing: Keep only amounts >= 25 before grouping. Expect South: 2 orders, 55 sales; North: 1 order, 40 sales.
2. Find repeat customers
Who placed more than one order?
Join first, then count orders for each customer.
Change one thing: Use HAVING COUNT(*) >= 1. Ben also appears with 1 order.
3. Find customers to contact
Who has never placed an order?
NOT EXISTS expresses the missing relationship directly.
Change one thing: Use EXISTS. Expect Ada and Ben.
4. Find the latest order status
What is the latest status of each order?
The event sequence defines recency. Rank first, then keep one row per order.
Change one thing: Use sequence ASC. All three statuses become New.
5. Find duplicate records
Which email appears more than once?
Count by the business key to find repeated records.
Change one thing: Change the third email to [email protected]. Expect no rows.
6. Compare actuals with targets
Which regions reached their target?
Compute actuals separately, match targets, then classify each result.
Change one thing: Set the South target to 50. Both regions return Met.