Skip to main content
Advancedhow it works

Split user events into sessions with a 30-minute inactivity gap.

Source: PostgreSQL: SELECT (clause processing)

Quick answerFree

Use LAG(event_time) OVER (PARTITION BY user_id ORDER BY event_time) to get the previous event. Flag a new session when there is no previous event or the gap is more than 30 minutes.

Detailed answer· 69 words

Pro

Unlock the full answer with Pro

Get a 69-word model answer, 3 key points and a visual explainer, plus 307 more SQL questions.

Key points· 3 points

Pro
Unlock with Pro

Visual explainer· animated, step by step

Pro
Unlock with Pro

+ 307 more SQL questions in Pro, each with the full answer.

Discussion