How would you write SQL queries using lag/lead and window functions to compute time-based features?
Use the provided users and activity_events tables. Return event-level features showing each event's previous and next event timestamps and the elapsed seconds between adjacent events.
event_id, user_id, user_name, event_type, event_at, previous_event_at, next_event_at, seconds_since_previous, and seconds_until_next.user_id with NULL user IDs last, then event_at and event_id.| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| user_name | VARCHAR(100) | Display name of the user |
| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique activity event identifier |
| user_id | INT | User associated with the event |
| event_type | VARCHAR(40) | Type of activity event |
| event_at | TIMESTAMP | Timestamp when the event occurred |