Skip to content

Commit 0d19238

Browse files
add 511
1 parent 8ba7179 commit 0d19238

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ Your ideas/fixes/algorithms are more than welcome!
835835
|571|[Find Median Given Frequency of Numbers](https://leetcode.com/problems/find-median-given-frequency-of-numbers/)|[Solution](../master/database/_571.sql) | || Hard |
836836
|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 |
837837
|569|[Median Employee Salary](https://leetcode.com/problems/median-employee-salary/)|[Solution](../master/database/_569.sql) | || Hard |
838+
|511|[Game Play Analysis I](https://leetcode.com/problems/game-play-analysis-i/)|[Solution](../master/database/_511.sql)||| Easy|
838839
|262|[Trips and Users](https://leetcode.com/problems/trips-and-users/)|[Solution](../master/database/_262.sql)||| Hard| Inner Join
839840
|197|[Rising Temperature](https://leetcode.com/problems/rising-temperature/)|[Solution](../master/database/_197.sql)| O(n^2)|O(n) | Easy|
840841
|196|[Delete Duplicate Emails](https://leetcode.com/problems/delete-duplicate-emails/)|[Solution](../master/database/_196.sql)| O(n^2)|O(n) | Easy|

database/_511.sql

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--511. Game Play Analysis I
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 an SQL query that reports the first login date 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 | first_login |
36+
--+-----------+-------------+
37+
--| 1 | 2016-03-01 |
38+
--| 2 | 2017-06-25 |
39+
--| 3 | 2016-03-02 |
40+
--+-----------+-------------+
41+
42+
--# Write your MySQL query statement below
43+
44+
select player_id, min(event_date) as first_login
45+
from Activity
46+
group by player_id

0 commit comments

Comments
 (0)