This question evaluates proficiency in SQL time-series and event-stream manipulation, focusing on window-function techniques for sessionization, timestamp arithmetic, and aggregation to produce session-level metrics, targeting Data Manipulation (SQL/Python) competencies relevant to data scientist roles.
Write a single ANSI-SQL query that (a) assigns per-user session_ids when the gap between consecutive events exceeds 30 minutes, (b) computes session_start, session_end, event_count, session_length_seconds, and next_session_gap_seconds (time from this session_end to the next session_start for the same user), and (c) uses window functions including LEAD at least once. Schema: