Skip to content
ML Academy

SQL and Python

Interview question

  • seniorlevel
  • 12 minsuggested time
  • 3Data analyst, Data scientist, ML engineer

A web-search event log events(customer_id, ts) has one row per search. Define a session as a run of events where no gap between consecutive events of the same customer exceeds 30 minutes. Write SQL that assigns a session number to every event and returns start, end and event count per session. What breaks when events arrive late?

Tests: Gaps-and-islands sessionisation with LAG and a cumulative sum; boundary conventions; reproducibility under late arrivals; thinking about the grain of the output.

Sign in to practise: answers are saved before model answers are shown.