Skip to content

Commit 575d88c

Browse files
refactor 534
1 parent 36ff44f commit 575d88c

File tree

1 file changed

+0
-47
lines changed

1 file changed

+0
-47
lines changed

database/_534.sql

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,3 @@
1-
--534. Game Play Analysis III
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 for each player and date, how many games played so far by the player. That is, the total number of games played by the player until that date. Check the example for clarity.
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-
--| 1 | 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 | event_date | games_played_so_far |
36-
--+-----------+------------+---------------------+
37-
--| 1 | 2016-03-01 | 5 |
38-
--| 1 | 2016-05-02 | 11 |
39-
--| 1 | 2017-06-25 | 12 |
40-
--| 3 | 2016-03-02 | 0 |
41-
--| 3 | 2018-07-03 | 5 |
42-
--+-----------+------------+---------------------+
43-
--For the player with id 1, 5 + 6 = 11 games played by 2016-05-02, and 5 + 6 + 1 = 12 games played by 2017-06-25.
44-
--For the player with id 3, 0 + 5 = 5 games played by 2018-07-03.
45-
--Note that for each player we only care about the days when the player logged in.
46-
47-
--# Write your MySQL query statement below
481
select a1.player_id, a1.event_date, sum(a2.games_played) as games_played_so_far from Activity a1
492
inner join Activity a2
503
on a1.player_id = a2.player_id and a1.event_date >= a2.event_date

0 commit comments

Comments
 (0)