Each row of Activity records one day on which a player logged in to a game. A player's install date is the first day they logged in. The day-1 retention of a date x is the number of players who installed on x and also logged in on the day after x, divided by the number of players who installed on x.
For every install date, report how many players installed on that date and the day-1 retention for that date, rounded to 2 decimal places.
Input Table(s)
Table Activity
| Column | Type | Meaning |
|---|
| player_id | INT | Player identifier. NOT NULL. |
| device_id | INT | Device the player logged in from. NOT NULL. |
| event_date | DATE | Day of the login. NOT NULL. |
| games_played | INT | Games the player played that day, 0 or more. NOT NULL. |
Primary key: (player_id, event_date), so a player has at most one row per day.
Output Contract
One row per install date, with these columns in this order:
| Column | Type | Meaning |
|---|
| install_dt | DATE | A date on which at least one player installed. |
| installs | INT | Number of players whose install date is install_dt. |
| Day1_retention | NUMERIC | Players installed on install_dt who logged in on the following calendar day, divided by installs, rounded to 2 decimal places. |
Order the rows by install_dt ascending. Each install date appears once, so this ordering is unique.
Example
Activity:
| player_id | device_id | event_date | games_played |
|---|
| 1 | 10 | 2024-01-01 | 3 |
| 1 | 10 | 2024-01-02 | 0 |
| 2 | 11 | 2024-01-01 | 5 |
| 2 | 11 | 2024-01-03 | 2 |
| 3 | 12 | 2024-01-01 | 1 |
| 4 | 13 | 2024-01-02 | 4 |
| 4 | 14 | 2024-01-03 | 2 |
| 5 | 15 | 2024-01-04 | 6 |
Expected output:
| install_dt | installs | Day1_retention |
|---|
| 2024-01-01 | 3 | 0.33 |
| 2024-01-02 | 1 | 1.00 |
| 2024-01-04 | 1 | 0.00 |
Players 1, 2 and 3 installed on 2024-01-01. Only player 1 logged in on 2024-01-02 (with zero games, which still counts), so the retention is 1/3, shown as 0.33. Player 2 came back on 2024-01-03, two days after installing, which does not count. Player 4 installed on 2024-01-02 and logged in on 2024-01-03 from a different device, giving 1.00. Player 5 installed on 2024-01-04 and never returned, giving 0.00. Nobody installed on 2024-01-03, so that date has no row even though players logged in on it.
Constraints and Clarifications
-
At most 10,000 rows.
player_id
is between 1 and 100.
-
No column contains NULL.
-
Every row counts as a login, including rows where
games_played
is 0.
-
The next day means the calendar day right after
install_dt
. A return two or more days later does not count toward day-1 retention.
-
Dates on which nobody installed do not appear in the output.
-
Show
Day1_retention
with two decimals, for example
0.50
,
1.00
or
0.00
.