Gaps, islands & sessionization
Exercise · SQL & Querying

Predict, then run it

Predict the output

reads(t, gate) = (1,in),(2,in),(3,out),(4,in). Split the 'in' reads into consecutive runs:

SELECT island, COUNT(*) AS len FROM (SELECT t - ROW_NUMBER() OVER (ORDER BY t) AS island FROM reads WHERE gate='in') GROUP BY island ORDER BY island;

Predict the exact output.