Measure Next-Day Return after Each Player’s First Login
Company: Microsoft
Role: Software Engineer
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
### Problem
Return fraction: the fraction of all players who logged in on the calendar day immediately after their first recorded login. Round to two decimal places. The denominator counts players, not activity rows; zero games still constitutes a login.
### Tables
Table: `Activity`
```text
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| player_id | int |
| device_id | int |
| event_date | date |
| games_played | int |
+--------------+---------+
(player_id, event_date) is the primary key (combination of columns with unique values) of this table.
This table shows the activity of players of some games.
Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on someday using some device.
```
### Constraints
`Activity` contains at least one row, so at least one player is present. Every event_date is a finite calendar date.
### Example
```text
Activity (player_id,device_id,event_date,games_played):
(1,2,2021-01-01,0), (1,3,2021-01-02,1), (1,3,2021-01-05,2),
(2,2,2021-02-01,2), (2,2,2021-02-03,2)
Output (fraction): (0.50)
```
### What a Strong Answer Covers
- Use each player's first recorded login and the calendar day immediately after it.
- Count each player once and round the fraction to two decimal places.
### Follow-up Questions
- How would you measure a return on the seventh calendar day?
- How would you compare return rates by the month of the first login?
Overview: Calculate the fraction of players who log in on the calendar day after their first login.
Return fraction: the fraction of all players who logged in on the calendar day immediately after their first recorded login. Round to two decimal places. The denominator counts players, not activity rows; zero games still constitutes a login.
Tables
Table: Activity
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| player_id | int |
| device_id | int |
| event_date | date |
| games_played | int |
+--------------+---------+
(player_id, event_date) is the primary key (combination of columns with unique values) of this table.
This table shows the activity of players of some games.
Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on someday using some device.
Constraints
Activity contains at least one row, so at least one player is present. Every event_date is a finite calendar date.