Given a table Activity that tracks player login activity and game sessions, write a SQL query to find the fraction of players that logged in again on the day after their first login.
The table has the following structure:
player_id: Unique identifier for each playerdevice_id: Device used for the sessionevent_date: Date of the login sessiongames_played: Number of games played in that session
Your query should return the percentage of players who logged in on consecutive days starting from their first login, rounded to 2 decimal places.
Table Schema
| Column Name | Type | Description |
|---|---|---|
player_id
PK
|
int | Unique identifier for each player |
device_id
|
int | Device used for the gaming session |
event_date
PK
|
date | Date when the player logged in |
games_played
|
int | Number of games played in that session |
Input & Output
| player_id | device_id | event_date | games_played |
|---|---|---|---|
| 1 | 2 | 2016-03-01 | 5 |
| 1 | 2 | 2016-03-02 | 6 |
| 2 | 3 | 2017-06-25 | 1 |
| 3 | 1 | 2016-03-01 | 0 |
| 3 | 4 | 2018-07-03 | 5 |
| fraction |
|---|
| 0.33 |
Player 1's first login was 2016-03-01 and returned on 2016-03-02 (next day) ✓. Player 2's first login was 2017-06-25 but has no record for 2017-06-26 ✗. Player 3's first login was 2016-03-01 but next login was in 2018 ✗. Result: 1 out of 3 players = 0.33
| player_id | device_id | event_date | games_played |
|---|---|---|---|
| 1 | 2 | 2016-03-01 | 0 |
| 1 | 2 | 2016-03-04 | 1 |
| 2 | 3 | 2017-06-25 | 2 |
| fraction |
|---|
| 0 |
Player 1's first login was 2016-03-01 but next login was 2016-03-04 (not consecutive) ✗. Player 2 only has one login record ✗. No players returned the day after their first login: 0 out of 2 players = 0.00
Constraints
-
1 ≤ player_id ≤ 1000 -
1 ≤ device_id ≤ 1000 -
event_dateis in format 'YYYY-MM-DD' -
games_played ≥ 0