Skip to content

JieYing16/sql-gym

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

SQL Gym 🗄️

A self-contained, Leetcode-style SQL practice page focused on the queries that matter for data engineering and machine learning engineering roles.

No login, no paywall, no build step — it's a single index.html file. Open it in a browser and start practicing.

What's inside

20 problems across three difficulty tiers, each with sample data, an editable scratch query box, a hint, a full solution, and a note on why the pattern matters in real pipelines.

Tier Topics
Easy Filtering, LEFT vs INNER JOIN (row-loss bugs), GROUP BY + COUNT, second-highest-salary (the NULL trick), duplicate-key detection, null-rate audit
Medium Top-N per group (RANK vs ROW_NUMBER), deduping a CDC feed to latest-per-entity, running totals, CASE-based pivots, day-over-day change with LAG, anti-joins (referential integrity), EXCEPT reconciliation, QUALIFY
Hard Sessionization (LAG → flag → running sum), gaps & islands (login streaks), rolling-window features, median per group, funnel conversion rates, SCD Type 2 validity ranges with LEAD

The set is deliberately weighted toward window functions and reshaping — the skills that separate "can write a SELECT" from "can build a feature table."

Features

  • Run your SQL for real — an in-browser SQLite engine (sql.js / WebAssembly) executes your query against the sample tables and shows the result grid
  • Check answer — compares your output against the expected result (order-insensitive) and auto-marks the problem solved when it matches
  • Filter by difficulty and by topic (joins, window, dedup, sessionization, …)
  • Progressive reveals: hint first, solution only when you're ready
  • Progress tracking saved in your browser (localStorage)
  • Light / dark theme

A note on the SQL dialect

Queries execute on SQLite, so write SQLite-compatible SQL. A couple of solutions show cross-dialect syntax for teaching (QUALIFY, PERCENTILE_CONT, DATE_SUB) — each of those also includes a portable form that runs here. The Check button always grades against a SQLite reference query.

The only external dependency is the sql.js engine, loaded from a CDN at runtime, so running queries needs an internet connection. Everything else (problems, styling, logic) is inlined and works offline.

Usage

# just open it
open index.html        # macOS
start index.html       # Windows

Or serve it and share via GitHub Pages (Settings → Pages → deploy from main / root).

License

MIT — do whatever you like with it.

About

Leetcode-style SQL practice gym — joins, window functions, dedup, sessionization.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages