← All coursesStart lesson →
SQL Operations Cases
Diagnose funnels, refunds, inventory and duplicate customer records.
intermediate · About 70 minutes · 4 lessons · 8 exercises + 1 project
Your finished work
Runnable queries, checked result tables and explanations for business edge cases.
All examples use fictional, synthetic business data. Practice standard: each exercise ≥70, final project ≥80.
The course
- Start lesson →
1. Count a funnel honestly
Count unique customers rather than repeated visits.
- Start lesson →
2. Account for partial refunds
Aggregate multiple refunds before calculating net revenue.
- Start lesson →
3. Flag inventory exceptions
Compare known quantities while separating missing counts.
- Start lesson →
4. Diagnose duplicate customer keys
Find shared nonblank emails without deleting records.
Final project
Deliver regional net revenue
Start the project →Preview the input
CREATE TABLE orders(order_id INTEGER, customer_id INTEGER, status TEXT, amount INTEGER, region TEXT, ordered_at TEXT);
INSERT INTO orders VALUES (1,1,'paid',120,'East','2026-09-01'),(2,2,'pending',140,'West','2026-09-02'),(3,1,'paid',100,'East','2026-09-03'),(4,3,'paid',180,'West','2026-09-03'),(5,99,'paid',80,'East','2026-09-04'),(6,NULL,'cancelled',0,NULL,'2026-09-04'),(7,2,'paid',120,'West','2026-09-05'),(8,4,'paid',30,'North','2026-09-06');
CREATE TABLE customers(customer_id INTEGER PRIMARY KEY,name TEXT,email TEXT);
INSERT INTO customers VALUES(1,'Avery','team@example.test'),(2,'Morgan','team@example.test'),(3,'Riley',NULL),(4,'Casey',''),(5,'Sky','sky@example.test');
CREATE TABLE returns(return_id INTEGER,order_id INTEGER,refund INTEGER);
INSERT INTO returns VALUES(1,1,20),(2,1,10),(3,4,180),(4,99,25);
CREATE TABLE inventory(sku TEXT,on_hand INTEGER,reorder_at INTEGER);
INSERT INTO inventory VALUES('PEN',5,10),('BOOK',20,10),('MUG',0,5),('BAG',NULL,4),('CARD',4,4);
CREATE TABLE events(event_id INTEGER,customer_id INTEGER,stage TEXT);
INSERT INTO events VALUES(1,1,'visit'),(2,1,'visit'),(3,1,'checkout'),(4,2,'visit'),(5,3,'visit'),(6,3,'checkout'),(7,4,'visit');