sql-gym
Six SQL exercises where the obvious query is a silent bug.
Most practice sites grade syntax. This one teaches judgment on realistically messy data — duplicate deliveries, broken foreign keys, timezone-shifted timestamps, refunds that still look like revenue. You'll write a query that looks right and learn why it isn't.
The exercises
- 01
First Touch
A MIN() query that's correct on SQLite and silently wrong on MySQL.
- 02
The Duplicate Trap
At-least-once delivery. DISTINCT and COUNT(*) both lie to you, in different directions.
- 03
The 40% Drop
Marketing says Tuesday signups fell off a cliff. The cliff is a timezone.
- 04
Refunds & Revenue
Does a refunded order count as revenue? Pick a side and write the query that defends it.
- 05
The Orphan Join
An INNER JOIN that silently eats $100 of revenue. Find the leak.
- 06
Sessionize
Group events into sessions with a 30-min gap rule. LAG + running sum — the cliffhanger.