Skip to content

Commit 4f3cba9

Browse files
add 512
1 parent 3f2c20c commit 4f3cba9

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ _If you like this project, please leave me a star._ ★
896896
|571|[Find Median Given Frequency of Numbers](https://leetcode.com/problems/find-median-given-frequency-of-numbers/)|[Solution](../master/database/_571.sql) || Hard |
897897
|570|[Managers with at Least 5 Direct Reports](https://leetcode.com/problems/managers-with-at-least-5-direct-reports/)|[Solution](../master/database/_570.sql) || Medium |
898898
|569|[Median Employee Salary](https://leetcode.com/problems/median-employee-salary/)|[Solution](../master/database/_569.sql) || Hard |
899+
|512|[Game Play Analysis II](https://leetcode.com/problems/game-play-analysis-ii/)|[Solution](../master/database/_512.sql)|| Easy|
899900
|511|[Game Play Analysis I](https://leetcode.com/problems/game-play-analysis-i/)|[Solution](../master/database/_511.sql)|| Easy|
900901
|262|[Trips and Users](https://leetcode.com/problems/trips-and-users/)|[Solution](../master/database/_262.sql)||Hard| Inner Join
901902
|197|[Rising Temperature](https://leetcode.com/problems/rising-temperature/)|[Solution](../master/database/_197.sql)| | Easy|

database/_512.sql

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--512. Game Play Analysis II
2+
--
3+
--Table: Activity
4+
--
5+
--+--------------+---------+
6+
--| Column Name | Type |
7+
--+--------------+---------+
8+
--| player_id | int |
9+
--| device_id | int |
10+
--| event_date | date |
11+
--| games_played | int |
12+
--+--------------+---------+
13+
--(player_id, event_date) is the primary key of this table.
14+
--This table shows the activity of players of some game.
15+
--Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.
16+
--
17+
--
18+
--Write a SQL query that reports the device that is first logged in for each player.
19+
--
20+
--The query result format is in the following example:
21+
--
22+
--Activity table:
23+
--+-----------+-----------+------------+--------------+
24+
--| player_id | device_id | event_date | games_played |
25+
--+-----------+-----------+------------+--------------+
26+
--| 1 | 2 | 2016-03-01 | 5 |
27+
--| 1 | 2 | 2016-05-02 | 6 |
28+
--| 2 | 3 | 2017-06-25 | 1 |
29+
--| 3 | 1 | 2016-03-02 | 0 |
30+
--| 3 | 4 | 2018-07-03 | 5 |
31+
--+-----------+-----------+------------+--------------+
32+
--
33+
--Result table:
34+
--+-----------+-----------+
35+
--| player_id | device_id |
36+
--+-----------+-----------+
37+
--| 1 | 2 |
38+
--| 2 | 3 |
39+
--| 3 | 1 |
40+
--+-----------+-----------+
41+
42+
--# Write your MySQL query statement below
43+
select player_id, device_id from Activity where
44+
(player_id, event_date)
45+
in
46+
(select player_id, min(event_date) from Activity group by player_id);

0 commit comments

Comments
 (0)