Session summary per user

hardPipelines~35 min · 4 tests · ridelog

The growth team wants a per-user engagement summary from the raw events table. Two problems sit in the raw data:

  1. Duplicate ingests. Some events were stored twice. A copy has the same user_id, event_type and event_ts as the original. Count each event once.
  2. No session id. A session is a run of a user’s events with no gap of more than 30 minutes between one event and the next. A gap of exactly 30 minutes stays in the same session.

Return one row per user with:

column type meaning
user_id integer the user
sessions integer number of sessions
events integer unique events across all sessions
avg_events_per_session decimal events / sessions, rounded to 2 decimals
longest_session_minutes decimal longest time from a session’s first event to its last, in minutes, rounded to 1 decimal

A session with one event lasts 0 minutes. Timestamps can carry seconds, so measure gaps and lengths as real durations, not by counting clock minutes.

Row order doesn’t matter.

Tables: events.

Learn the ideaRead the lesson →
solution.sqlDuckDB · ridelog

Press ⌘ ↵ or Run to check the visible tests. Submit runs the hidden ones too. Everything runs in your browser.

⌘ ↵ to run