leetcode511. gameplay analysis I (SQL)

Activity Table Activity:

+ --------- + -------------- +
| Column the Name | Type |
+ -------------- + - + -------
| player_id | int |
| DEVICE_ID | int |
| event_date | DATE |
| games_played | int |
+ ------ + -------------- + ---
table's primary key is (player_id, event_date).
This table shows some gamers behavioral activity in the gaming platform.
Each row of data records the number of games a player before exiting the platform, the day after using the same device to log platform open (possibly 0).
 

Write a SQL query statement to get the first date of each player landing platform.

Results format is as follows:

Activity 表:
+-----------+-----------+------------+--------------+
| 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            |
+-----------+-----------+------------+--------------+

Result 表:
+-----------+-------------+
| player_id | first_login |
+-----------+-------------+
| 1         | 2016-03-01  |
| 2         | 2017-06-25  |
| 3         | 2016-03-02  |
+-----------+-------------+

Ideas: grouped according to the player id, id and minimum time to check.

select player_id,min(event_date) as 'first_login'
from activity
group by player_id 

 

Published 552 original articles · won praise 10000 + · views 1.32 million +

Guess you like

Origin blog.csdn.net/hebtu666/article/details/104322319