Gaps, islands & sessionization
Exercise · SQL & Querying

Predict, then run it

Predict the output

pings(sid, ts) = (1,0),(1,10),(2,20),(2,25) — sessionized already. Duration per session is the elapsed span:

SELECT sid, MAX(ts) - MIN(ts) AS mins FROM pings GROUP BY sid ORDER BY sid;

Predict the exact output.