The Game Play Analysis I interview question is a SQL task where you are given an Activity table. This table logs player logins, containing player_id, device_id, event_date, and games_played. Your goal is to write a query that reports the first login date for each player.
Companies like Amazon and Apple use this Database coding problem as a foundational test of your SQL aggregation skills. It evaluates if you know how to use the GROUP BY clause in conjunction with an aggregate function like MIN(). It's a very common real-world requirement for user analytics (e.g., finding a user's sign-up date or first action).
This problem follows a basic Grouping and Aggregation pattern.
GROUP BY player_id to aggregate the rows for each individual player.MIN(event_date) function to find the earliest date in each group.player_id and the calculated minimum date, aliasing the column as first_login.Activity Table:
| player_id | event_date |
|---|---|
| 1 | 2016-03-01 |
| 1 | 2016-05-02 |
| 2 | 2017-06-25 |
player_id:
MIN for each:
MIN(event_date) column to first_login as required by the problem description.device_id as well without putting it in the GROUP BY clause, which will cause a SQL error in strict modes (like ONLY_FULL_GROUP_BY in MySQL).LIMIT, which doesn't work when you need the first date for every player, not just one.Always double-check the required output column names. SQL judging systems are very strict about aliases. This simple MIN() + GROUP BY pattern is the stepping stone to harder Window Function problems.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Swap Sex of Employees | Easy | Solve | |
| Fix Names in a Table | Easy | Solve | |
| Not Boring Movies | Easy | Solve | |
| Primary Department for Each Employee | Easy | Solve | |
| Queries Quality and Percentage | Easy | Solve |