Game Play Analysis V - Problem
Game Play Analysis V is an advanced SQL problem that challenges you to calculate player retention rates for a gaming platform.
You're given an
Key Concepts:
โข Install date: The first day a player ever logged in
โข Day one retention: Percentage of players who return the day after installing
Your Mission: For each install date, calculate:
1. Total number of players who installed on that date
2. Day one retention rate (rounded to 2 decimal places)
This metric is crucial for game companies to measure user engagement and optimize their onboarding experience!
You're given an
Activity table that tracks player login sessions:| Column Name | Type |
|---|---|
| player_id | int |
| device_id | int |
| event_date | date |
| games_played | int |
Key Concepts:
โข Install date: The first day a player ever logged in
โข Day one retention: Percentage of players who return the day after installing
Your Mission: For each install date, calculate:
1. Total number of players who installed on that date
2. Day one retention rate (rounded to 2 decimal places)
This metric is crucial for game companies to measure user engagement and optimize their onboarding experience!
Input & Output
example_1.sql โ Basic Retention Analysis
$
Input:
Activity table:
+----------+-----------+------------+--------------+
| 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 | 2016-07-03 | 5 |
+----------+-----------+------------+--------------+
โบ
Output:
+------------+---------+----------------+
| install_date| installs| day1_retention |
+------------+---------+----------------+
| 2016-03-01 | 2 | 0.50 |
| 2016-07-03 | 1 | 0.00 |
| 2017-06-25 | 1 | 0.00 |
+------------+---------+----------------+
๐ก Note:
On 2016-03-01: 2 players installed (players 1 and 3). Only player 1 returned on 2016-03-02, so retention = 1/2 = 0.50. Other install dates had 0% retention as no players returned the next day.
example_2.sql โ Perfect Retention
$
Input:
Activity table:
+----------+-----------+------------+--------------+
| player_id| device_id | event_date | games_played |
+----------+-----------+------------+--------------+
| 1 | 1 | 2020-01-01 | 3 |
| 1 | 1 | 2020-01-02 | 2 |
| 2 | 2 | 2020-01-01 | 1 |
| 2 | 2 | 2020-01-02 | 4 |
+----------+-----------+------------+--------------+
โบ
Output:
+------------+---------+----------------+
| install_date| installs| day1_retention |
+------------+---------+----------------+
| 2020-01-01 | 2 | 1.00 |
+------------+---------+----------------+
๐ก Note:
Both players installed on 2020-01-01 and both returned on 2020-01-02, resulting in perfect 100% day-1 retention.
example_3.sql โ Zero Retention Edge Case
$
Input:
Activity table:
+----------+-----------+------------+--------------+
| player_id| device_id | event_date | games_played |
+----------+-----------+------------+--------------+
| 1 | 1 | 2021-01-15 | 2 |
| 2 | 2 | 2021-01-15 | 0 |
| 3 | 3 | 2021-01-16 | 1 |
+----------+-----------+------------+--------------+
โบ
Output:
+------------+---------+----------------+
| install_date| installs| day1_retention |
+------------+---------+----------------+
| 2021-01-15 | 2 | 0.00 |
| 2021-01-16 | 1 | 0.00 |
+------------+---------+----------------+
๐ก Note:
Players installed but none returned the next day. All retention rates are 0.00, showing that even players with 0 games_played count as installs.
Constraints
- 1 โค player_id, device_id โค 104
- event_date is a valid date between 2016-02-28 and 2021-12-31
- 0 โค games_played โค 1000
- The combination (player_id, event_date) is unique
- A player's install date is their first recorded event_date
Visualization
Tap to expand
Understanding the Visualization
1
Identify Install Dates
Find each player's first login date using window functions
2
Match Next-Day Activity
Self-join to find players who returned the day after installing
3
Calculate Retention
Group by install date and compute retention percentage
4
Format Results
Round to 2 decimal places and order by install date
Key Takeaway
๐ฏ Key Insight: Use window functions to identify install dates efficiently, then self-join with date arithmetic to calculate retention rates in a single optimized query.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code