Google Analytics defines a session by inactivity: a user's events belong to the same session until there is a gap of MORE than 30 minutes (1800 seconds) between two consecutive events of that user. A gap of exactly 30 minutes does not start a new session. Sessions can span midnight. Write an SQL query that returns, for every user, `user_id`, `session_count` (the number of sessions) and `largest_session_events` (the number of events in the user's biggest session). Order the results by `user_id` ascending.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.