Imagine you're a data analyst at a gaming company trying to measure player retention! ๐ฎ
You have an Activity table that tracks every time players log in and play games. Your mission is to calculate the fraction of players who came back the very next day after their first login.
Table Structure:
| Column Name | Type |
|---|---|
| player_id | int |
| device_id | int |
| event_date | date |
| games_played | int |
The (player_id, event_date) combination is unique, meaning each player can only have one record per day.
Your Goal: Find what percentage of players logged in on consecutive days starting from their very first login. Return this as a decimal rounded to 2 places.
Example: If 100 players joined your game, and 33 of them came back the next day, your answer would be 0.33.
Input & Output
Visualization
Time & Space Complexity
Single pass with window function and join, optimized by database engine
Temporary space for window function computation
Constraints
- 1 โค Activity table rows โค 104
- 1 โค player_id, device_id โค 104
- event_date is in YYYY-MM-DD format
- 0 โค games_played โค 1000
- (player_id, event_date) is the primary key of the table