Skip to content

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.

01

Group and aggregate

Collapse many rows into one row per group, and know exactly what one row of the result stands for.

26 questions
02

Joins

Combine tables with inner and outer joins, and check that the join does not multiply your rows.

26 questions
03

Ranking and top N

Rank rows with window functions, keep the top N overall or per group, and decide what happens on ties.

24 questions
04

Running 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 questions
05

CTEs and subqueries

Split a hard question into named steps with CTEs, and know when a subquery is the simpler tool.

14 questions
06

Ratios and percentages

Compute shares, rates and percentages correctly, with the right denominator, no integer division and no divide by zero.

15 questions
07

Conditional aggregation

Put CASE or FILTER inside an aggregate to count, sum or pivot several slices of the data in one pass.

15 questions
08

Dates and time

Truncate timestamps into days, weeks and months, filter by date ranges safely and do date arithmetic.

15 questions
09

NULL handling

Know how NULL behaves in filters, joins, aggregates and sorting, and write queries that stay correct when data is missing.

11 questions
10

Period over period

Compare each month or week with the one before, or with the same period last year, and compute growth correctly.

10 questions
11

Self joins

Join a table to itself to compare rows with each other, such as employees with managers or events with later events.

9 questions
12

Rows with no match

Find customers with no orders, products never sold and other missing rows, and avoid the NOT IN NULL trap.

9 questions
13

Deduplication and latest row

Find repeated rows and keep exactly one per key, usually the latest, with ROW_NUMBER and a clear tie-breaker.

10 questions
14

Cohorts and retention

Group users by the month they started, then count how many come back in each later month.

10 questions
15

Funnels

Count how many users reach each step in order, such as view, cart and purchase, and compute step-to-step conversion.

8 questions
16

Gaps and islands

Find streaks of consecutive days, sessions and missing ranges by subtracting a row number from the value.

6 questions
17

Medians and percentiles

Compute medians, quartiles and p90 with PERCENTILE_CONT, and know when an average hides the real story.

5 questions
18

Text and set operations

Clean and split text, match patterns, and combine result sets with UNION, INTERSECT and EXCEPT.

4 questions
19

Analytics 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 questions
Cheat sheet

SQL dialect cheat sheet

How the same analyst tasks are written in PostgreSQL, Snowflake, Databricks, BigQuery, SQL Server, MySQL and Redshift.