Given a series of user events, how would you calculate session duration using SQL?
Assume a new session begins when a user has more than 30 minutes of inactivity. Exclude events with a missing user ID or event timestamp, and return one row per session.
user_id, session_number, session_start, session_end, and duration_secondsuser_id, then session_start, then session_number| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique identifier for the event |
| user_id | VARCHAR(30) | Identifier of the user who generated the event |
| event_time | TIMESTAMPTZ | Timestamp when the event occurred |
| event_name | VARCHAR(40) | Name of the recorded user event |