Gaps, islands & sessionization
Exercise · SQL & Querying

Predict, then run it

Predict the output

matches(player, d) holds ladder-match days per player: Ada played on days 1, 5, 40. Flag each match that follows a gap of more than 21 days:

SELECT player, d FROM (SELECT player, d, d - LAG(d) OVER (PARTITION BY player ORDER BY d) AS gap FROM matches) WHERE gap > 21 ORDER BY d;

Predict the exact output.