Interview Questions/SQL/Game Play Analysis IV

Game Play Analysis IV

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Description

You have an Activity table that logs when players played games. Each player has a first login date (the minimum event_date for that player). Write a SQL query to report the fraction of players who logged in again the day immediately after their first login date. Round the result to 2 decimal places. (player_id, event_date) is the primary key.

Database Schema

Activity

Column NameTypeDescription
player_idINTPlayer identifier
device_idINTDevice used
event_dateDATEDate of activity
games_playedINTNumber of games played on that date

Example

Activity

player_iddevice_idevent_dategames_played
122016-03-015
122016-03-026
232017-06-251
312016-03-020
342018-07-035

Output

fraction
0.33

Explanation:

Player 1 logged in on 2016-03-01 (first login) and again on 2016-03-02 (next day). Players 2 and 3 did not log in the day after their first login. So 1 out of 3 = 0.33.

Approach hint

Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

SQL Editor
Loading...

Activity

player_iddevice_idevent_dategames_played
122016-03-015
122016-03-026
232017-06-251
312016-03-020
342018-07-035

Output

fraction
0.33