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

  1. 01

    First Touch

    A MIN() query that's correct on SQLite and silently wrong on MySQL.

  2. 02

    The Duplicate Trap

    At-least-once delivery. DISTINCT and COUNT(*) both lie to you, in different directions.

  3. 03

    The 40% Drop

    Marketing says Tuesday signups fell off a cliff. The cliff is a timezone.

  4. 04

    Refunds & Revenue

    Does a refunded order count as revenue? Pick a side and write the query that defends it.

  5. 05

    The Orphan Join

    An INNER JOIN that silently eats $100 of revenue. Find the leak.

  6. 06

    Sessionize

    Group events into sessions with a 30-min gap rule. LAG + running sum — the cliffhanger.