Learn
The patterns behind every SQL screen
Each lesson is a few minutes long: when the pattern applies, the shape of the query, the traps, and examples you can run right on the page. Then practise with the questions for that pattern.
Group and aggregate
Collapse many rows into one row per group, and know exactly what one row of the result stands for.
26 questions02Joins
Combine tables with inner and outer joins, and check that the join does not multiply your rows.
26 questions03Ranking and top N
Rank rows with window functions, keep the top N overall or per group, and decide what happens on ties.
24 questions04Running totals, LAG and LEAD
Use window frames for running sums and moving averages, and LAG or LEAD to compare a row with the one before or after.
18 questions05CTEs and subqueries
Split a hard question into named steps with CTEs, and know when a subquery is the simpler tool.
14 questions06Ratios and percentages
Compute shares, rates and percentages correctly, with the right denominator, no integer division and no divide by zero.
15 questions07Conditional aggregation
Put CASE or FILTER inside an aggregate to count, sum or pivot several slices of the data in one pass.
15 questions08Dates and time
Truncate timestamps into days, weeks and months, filter by date ranges safely and do date arithmetic.
15 questions09NULL handling
Know how NULL behaves in filters, joins, aggregates and sorting, and write queries that stay correct when data is missing.
11 questions10Period over period
Compare each month or week with the one before, or with the same period last year, and compute growth correctly.
10 questions11Self joins
Join a table to itself to compare rows with each other, such as employees with managers or events with later events.
9 questions12Rows with no match
Find customers with no orders, products never sold and other missing rows, and avoid the NOT IN NULL trap.
9 questions13Deduplication and latest row
Find repeated rows and keep exactly one per key, usually the latest, with ROW_NUMBER and a clear tie-breaker.
10 questions14Cohorts and retention
Group users by the month they started, then count how many come back in each later month.
10 questions15Funnels
Count how many users reach each step in order, such as view, cart and purchase, and compute step-to-step conversion.
8 questions16Gaps and islands
Find streaks of consecutive days, sessions and missing ranges by subtracting a row number from the value.
6 questions17Medians and percentiles
Compute medians, quartiles and p90 with PERCENTILE_CONT, and know when an average hides the real story.
5 questions18Text and set operations
Clean and split text, match patterns, and combine result sets with UNION, INTERSECT and EXCEPT.
4 questions19Analytics engineering
Check the grain of a table, read type 2 history, build a date spine and do as-of joins to the latest value before a date.
20 questionsSQL dialect cheat sheet
How the same analyst tasks are written in PostgreSQL, Snowflake, Databricks, BigQuery, SQL Server, MySQL and Redshift.