Average Session Time per User

Problem Given web event logs (user_id, event_time, page/url), write SQL to compute the average session time per user, where a session is a burst of activity separated from the next by a gap (e.g. > 30 minutes of inactivity starts a new session).

Input / Output

  • Input: events(user_id, event_time) table.
  • Output: (user_id, avg_session_duration).

Constraints

  • Sessionization must be done in SQL — expect window functions, not application code.

Example

  • User A with events at 10:00, 10:10, 11:00 (gap 50 min) → two sessions: 10 min and 0 min → average 5 min.
asked …
LeaderboardSalaryAccount