17. First Login Analysis

In any gaming platform, it's important to know when each player first started using the platform. This helps in tracking user lifecycle, cohort analysis, and retention strategies.

You are given a table named Activity:

╔═════════════╦══════════╗
β•‘ Column Name β•‘   Type   β•‘
╠═════════════╬══════════╣
β•‘  player_id  β•‘   int    β•‘
║─────────────┼──────────║
β•‘  device_id  β•‘   int    β•‘
║─────────────┼──────────║
β•‘ event_date  β•‘   date   β•‘
║─────────────┼──────────║
β•‘games_played β•‘   int    β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•
  • player_id: the unique ID of the player
  • device_id: the device used to play
  • event_date: the date of the login
  • games_played: how many games the player played on that day.
  • The primary key is (player_id, event_date). A player can appear only once per day in this table. A player may use multiple devices, but per day only one row is recorded.

Write a query to get the earliest (first) login date for each player. Return the result ordered by player_id.

Example 1:

Example:

Input:

Activity Table

╔═══════════╦═══════════╦════════════╦══════════════╗
β•‘ player_id β•‘ device_id β•‘ event_date β•‘ games_played β•‘
╠═══════════╬═══════════╬════════════╬══════════════╣
β•‘     1     β•‘     2     β•‘ 2016-03-01 β•‘      5       β•‘
║───────────┼───────────┼────────────┼──────────────║
β•‘     1     β•‘     2     β•‘ 2016-05-02 β•‘      6       β•‘
║───────────┼───────────┼────────────┼──────────────║
β•‘     2     β•‘     3     β•‘ 2017-06-25 β•‘      1       β•‘
║───────────┼───────────┼────────────┼──────────────║
β•‘     3     β•‘     1     β•‘ 2016-03-02 β•‘      0       β•‘
║───────────┼───────────┼────────────┼──────────────║
β•‘     3     β•‘     4     β•‘ 2018-07-03 β•‘      5       β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Expected Output:

╔═══════════╦═════════════╗
β•‘ player_id β•‘ first_login β•‘
╠═══════════╬═════════════╣
β•‘     1     β•‘ 2016-03-01  β•‘
║───────────┼─────────────║
β•‘     2     β•‘ 2017-06-25  β•‘
║───────────┼─────────────║
β•‘     3     β•‘ 2016-03-02  β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Explanation:

  • Player 1 logged in on 2016-03-01 and 2016-05-02. Earliest = 2016-03-01
  • Player 2 has only one login on 2017-06-25. Earliest = 2017-06-25
  • Player 3 logged in on 2016-03-02 and 2018-07-03. Earliest = 2016-03-02

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Hints

0
Β 
Test Case

Input:

Activity