◆ Data Science · Case Study 05

UFC in SQL: a live query console

Thirty years of UFC fights, modeled into a real relational database that runs entirely in your browser. Read the analyst queries and their results, from simple joins to window functions, then scroll to the console and run your own SQL against the same database.

🗄️
This is a real database, not a mockup

A 2.3 MB SQLite database of every UFC event, fighter, and bout is loaded into your browser with sql.js (SQLite compiled to WebAssembly). Every result below is computed live by actually running the SQL, and the console at the bottom runs whatever you type. Loading the database…

STEP 1

The schema

The raw source is a flat scrape of ufcstats.com. The first job of an analyst is modeling: turning that pile into normalized tables with keys, so each fighter, event, and fight is stored once and linked by id. bouts is the hub, pointing to an event, two fighters, and a winner, with matching rows in fight_stats.

STEP 2

The questions, answered in SQL

Eight real questions, each matched to the SQL technique that answers it: joins, grouping, conditional aggregation, CTEs, self-joins, date bucketing, and window functions. Every query runs live against the database above, so these are the actual results, not screenshots.

STEP 3

Your turn: the live console

Write any query and run it against the real database. Start from an example, or explore the schema above. This is the same engine, so window functions, CTEs, and joins all work.

Data: ufcstats.com (public scrape) · Database, schema design, queries, and console by Carlos Abel Vivanco / AbleV Labs · Read the full notebook → · Back to the case study →