
Trace seven checkouts through payment status and account eligibility. Reconcile 400 in paid sales to 300 in registered-buyer revenue.
Use an inner average as a single comparison value. See how the population filter and the equality boundary affect the qualifying orders.
Trace the outer customer key into an EXISTS test and build a recipient list with one row per buyer.
See why a NULL guest key makes NOT IN lose eligible customers. Use NOT EXISTS to recover accounts with cancellations or no orders.
Move from receipt grain to buyer grain inside FROM. Compare the average paid receipt with the average active buyer total.
Write and inspect a common table expression. Point the final SELECT at the eligible receipts to validate counts and revenue.
Build buyer totals and a shared benchmark, then return above-average buyers with a deterministic tie order.
Introduce an exact-boundary buyer and audit expected versus actual rows. Detect missing records, incorrect amounts and duplicates.
Which customers spend more than average? Before you write the query, you have to decide what counts as a sale, whether guest checkouts belong in the calculation, and whether each order or each buyer gets one vote in the average. In this short SQL course, you will answer that question for a small shop and trace each result back to the original receipts.
Start with a scalar subquery to find unusually large orders. Then use correlated EXISTS and NOT EXISTS to build two customer lists. A guest checkout with a missing account identifier shows exactly how NOT IN can hide customers who should appear in your report.
Next, group purchases by buyer inside a derived table. Rewrite the eligibility rule as a common table expression, inspect the rows it returns, and chain named steps into a report with a shared benchmark. Finish by adding a buyer who lands exactly on the threshold and checking your expected results for missing rows, extra copies and incorrect amounts.
Each lecture pairs readable SQL with the rows it produces. The downloadable SQLite database, setup script, worked examples, eight practice challenges and answer key let you repeat every calculation in your own editor. You should already be comfortable with SELECT, WHERE and basic aggregation. By the end, you will have a buyer-spend report you can explain, change and verify one step at a time.
AI tools assisted in preparing course artwork and instructional materials.