Identifying User Sessions
Start Timer
0:00:00
Suppose you have an events table that tracks user activities on a website. Write a query to identify and label each event with a session number. All events in the same session should be labeled with the same session number.
Note: A session is defined as a series of consecutive events for a user that are within 60 minutes of each other.
i.e. If a user has a series of events at 00:01:00, 00:30:00, 01:01:00, this would be considered 1 session but a series of events at 00:01:00, 00:30:00, 01:31:00 would be 2 sessions.
Example:
Input:
events table
| Column | Type |
|---|---|
| id | INTEGER |
| created_at | DATETIME |
| user_id | INTEGER |
| event | VARCHAR |
Output:
| Column | Type |
|---|---|
| created_at | DATETIME |
| user_id | INTEGER |
| event | VARCHAR |
| session_id | INTEGER |
.
.
.
.
.
.
.
.
.
Comments