SpinTheMic
Pro

Explain it in 60 seconds

Sessionization in SQL

Data Engineering · SQL · Experienced

How would you split user events into sessions with a 30-minute inactivity rule using SQL?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Order events per user by timestamp.
  • Use LAG to get the previous event time.
  • Flag a new session when the gap is over 30 minutes or there's no previous event.
  • Running SUM of the flag per user gives a session number.
  • Build session_id from user_id and session number.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics