Skip to content

Commit e4ed7cd

Browse files
committed
feat: add paid only questions
1 parent 0b84082 commit e4ed7cd

File tree

675 files changed

+28405
-16201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

675 files changed

+28405
-16201
lines changed

solution/0500-0599/0511.Game Play Analysis I/README.md

+45-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,49 @@
66

77
<!-- 这里写题目描述 -->
88

9-
None
9+
<p>活动表&nbsp;<code>Activity</code>:</p>
10+
11+
<pre>
12+
+--------------+---------+
13+
| Column Name | Type |
14+
+--------------+---------+
15+
| player_id | int |
16+
| device_id | int |
17+
| event_date | date |
18+
| games_played | int |
19+
+--------------+---------+
20+
表的主键是 (player_id, event_date)。
21+
这张表展示了一些游戏玩家在游戏平台上的行为活动。
22+
每行数据记录了一名玩家在退出平台之前,当天使用同一台设备登录平台后打开的游戏的数目(可能是 0 个)。
23+
</pre>
24+
25+
<p>&nbsp;</p>
26+
27+
<p>写一条 SQL&nbsp;查询语句获取每位玩家 <strong>第一次登陆平台的日期</strong>。</p>
28+
29+
<p>查询结果的格式如下所示:</p>
30+
31+
<pre>
32+
Activity 表:
33+
+-----------+-----------+------------+--------------+
34+
| player_id | device_id | event_date | games_played |
35+
+-----------+-----------+------------+--------------+
36+
| 1 | 2 | 2016-03-01 | 5 |
37+
| 1 | 2 | 2016-05-02 | 6 |
38+
| 2 | 3 | 2017-06-25 | 1 |
39+
| 3 | 1 | 2016-03-02 | 0 |
40+
| 3 | 4 | 2018-07-03 | 5 |
41+
+-----------+-----------+------------+--------------+
42+
43+
Result 表:
44+
+-----------+-------------+
45+
| player_id | first_login |
46+
+-----------+-------------+
47+
| 1 | 2016-03-01 |
48+
| 2 | 2017-06-25 |
49+
| 3 | 2016-03-02 |
50+
+-----------+-------------+
51+
</pre>
1052

1153
## 解法
1254

@@ -16,8 +58,8 @@ None
1658

1759
### **SQL**
1860

19-
```
20-
select player_id, min(event_date) as first_login from Activity group by player_id
61+
```sql
62+
2163
```
2264

2365
<!-- tabs:end -->

solution/0500-0599/0511.Game Play Analysis I/README_EN.md

+45-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,58 @@
44

55
## Description
66

7-
None
7+
<p>Table:&nbsp;<code>Activity</code></p>
8+
9+
<pre>
10+
+--------------+---------+
11+
| Column Name | Type |
12+
+--------------+---------+
13+
| player_id | int |
14+
| device_id | int |
15+
| event_date | date |
16+
| games_played | int |
17+
+--------------+---------+
18+
(player_id, event_date) is the primary key of this table.
19+
This table shows the activity of players of some game.
20+
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.
21+
</pre>
22+
23+
<p>&nbsp;</p>
24+
25+
<p>Write an SQL query that reports the&nbsp;<strong>first login date</strong> for each player.</p>
26+
27+
<p>The query result format is in the following example:</p>
28+
29+
<pre>
30+
Activity table:
31+
+-----------+-----------+------------+--------------+
32+
| player_id | device_id | event_date | games_played |
33+
+-----------+-----------+------------+--------------+
34+
| 1 | 2 | 2016-03-01 | 5 |
35+
| 1 | 2 | 2016-05-02 | 6 |
36+
| 2 | 3 | 2017-06-25 | 1 |
37+
| 3 | 1 | 2016-03-02 | 0 |
38+
| 3 | 4 | 2018-07-03 | 5 |
39+
+-----------+-----------+------------+--------------+
40+
41+
Result table:
42+
+-----------+-------------+
43+
| player_id | first_login |
44+
+-----------+-------------+
45+
| 1 | 2016-03-01 |
46+
| 2 | 2017-06-25 |
47+
| 3 | 2016-03-02 |
48+
+-----------+-------------+
49+
</pre>
850

951
## Solutions
1052

1153
<!-- tabs:start -->
1254

1355
### **SQL**
1456

15-
```
16-
select player_id, min(event_date) as first_login from Activity group by player_id
57+
```sql
58+
1759
```
1860

1961
<!-- tabs:end -->

solution/0500-0599/0511.Game Play Analysis I/Solution.sql

-1
This file was deleted.

solution/0500-0599/0512.Game Play Analysis II/README.md

+42-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,46 @@
66

77
<!-- 这里写题目描述 -->
88

9-
None
9+
<p>Table:&nbsp;<code>Activity</code></p>
10+
11+
<pre>
12+
+--------------+---------+
13+
| Column Name | Type |
14+
+--------------+---------+
15+
| player_id | int |
16+
| device_id | int |
17+
| event_date | date |
18+
| games_played | int |
19+
+--------------+---------+
20+
(player_id, event_date) 是这个表的两个主键
21+
这个表显示的是某些游戏玩家的游戏活动情况
22+
每一行是在某天使用某个设备登出之前登录并玩多个游戏(可能为0)的玩家的记录
23+
</pre>
24+
25+
<p>请编写一个 SQL 查询,描述每一个玩家首次登陆的设备名称</p>
26+
27+
<p>查询结果格式在以下示例中:</p>
28+
29+
<pre>
30+
Activity table:
31+
+-----------+-----------+------------+--------------+
32+
| player_id | device_id | event_date | games_played |
33+
+-----------+-----------+------------+--------------+
34+
| 1 | 2 | 2016-03-01 | 5 |
35+
| 1 | 2 | 2016-05-02 | 6 |
36+
| 2 | 3 | 2017-06-25 | 1 |
37+
| 3 | 1 | 2016-03-02 | 0 |
38+
| 3 | 4 | 2018-07-03 | 5 |
39+
+-----------+-----------+------------+--------------+
40+
41+
Result table:
42+
+-----------+-----------+
43+
| player_id | device_id |
44+
+-----------+-----------+
45+
| 1 | 2 |
46+
| 2 | 3 |
47+
| 3 | 1 |
48+
+-----------+-----------+</pre>
1049

1150
## 解法
1251

@@ -16,8 +55,8 @@ None
1655

1756
### **SQL**
1857

19-
```
20-
select player_id, device_id from Activity where (player_id, event_date) in ((select player_id, min(event_date) from Activity group by player_id))
58+
```sql
59+
2160
```
2261

2362
<!-- tabs:end -->

solution/0500-0599/0512.Game Play Analysis II/README_EN.md

+44-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,57 @@
44

55
## Description
66

7-
None
7+
<p>Table:&nbsp;<code>Activity</code></p>
8+
9+
<pre>
10+
+--------------+---------+
11+
| Column Name | Type |
12+
+--------------+---------+
13+
| player_id | int |
14+
| device_id | int |
15+
| event_date | date |
16+
| games_played | int |
17+
+--------------+---------+
18+
(player_id, event_date) is the primary key of this table.
19+
This table shows the activity of players of some game.
20+
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.
21+
</pre>
22+
23+
<p>&nbsp;</p>
24+
25+
<p>Write a&nbsp;SQL query that reports&nbsp;the <strong>device</strong>&nbsp;that is first logged in&nbsp;for each player.</p>
26+
27+
<p>The query result format is in the following example:</p>
28+
29+
<pre>
30+
Activity table:
31+
+-----------+-----------+------------+--------------+
32+
| player_id | device_id | event_date | games_played |
33+
+-----------+-----------+------------+--------------+
34+
| 1 | 2 | 2016-03-01 | 5 |
35+
| 1 | 2 | 2016-05-02 | 6 |
36+
| 2 | 3 | 2017-06-25 | 1 |
37+
| 3 | 1 | 2016-03-02 | 0 |
38+
| 3 | 4 | 2018-07-03 | 5 |
39+
+-----------+-----------+------------+--------------+
40+
41+
Result table:
42+
+-----------+-----------+
43+
| player_id | device_id |
44+
+-----------+-----------+
45+
| 1 | 2 |
46+
| 2 | 3 |
47+
| 3 | 1 |
48+
+-----------+-----------+</pre>
849

950
## Solutions
1051

1152
<!-- tabs:start -->
1253

1354
### **SQL**
1455

15-
```
16-
select player_id, device_id from Activity where (player_id, event_date) in ((select player_id, min(event_date) from Activity group by player_id))
56+
```sql
57+
1758
```
1859

1960
<!-- tabs:end -->

solution/0500-0599/0512.Game Play Analysis II/Solution.sql

-1
This file was deleted.

solution/0500-0599/0534.Game Play Analysis III/README.md

+50-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,54 @@
66

77
<!-- 这里写题目描述 -->
88

9-
None
9+
<p>Table:&nbsp;<code>Activity</code></p>
10+
11+
<pre>
12+
+--------------+---------+
13+
| Column Name | Type |
14+
+--------------+---------+
15+
| player_id | int |
16+
| device_id | int |
17+
| event_date | date |
18+
| games_played | int |
19+
+--------------+---------+
20+
(player_id,event_date)是此表的主键。
21+
这张表显示了某些游戏的玩家的活动情况。
22+
每一行是一个玩家的记录,他在某一天使用某个设备注销之前登录并玩了很多游戏(可能是 0 )。
23+
</pre>
24+
25+
<p>&nbsp;</p>
26+
27+
<p>编写一个 SQL 查询,同时报告每组玩家和日期,以及玩家到目前为止玩了多少游戏。也就是说,在此日期之前玩家所玩的游戏总数。详细情况请查看示例。</p>
28+
29+
<p>查询结果格式如下所示:</p>
30+
31+
<pre>
32+
Activity table:
33+
+-----------+-----------+------------+--------------+
34+
| player_id | device_id | event_date | games_played |
35+
+-----------+-----------+------------+--------------+
36+
| 1 | 2 | 2016-03-01 | 5 |
37+
| 1 | 2 | 2016-05-02 | 6 |
38+
| 1 | 3 | 2017-06-25 | 1 |
39+
| 3 | 1 | 2016-03-02 | 0 |
40+
| 3 | 4 | 2018-07-03 | 5 |
41+
+-----------+-----------+------------+--------------+
42+
43+
Result table:
44+
+-----------+------------+---------------------+
45+
| player_id | event_date | games_played_so_far |
46+
+-----------+------------+---------------------+
47+
| 1 | 2016-03-01 | 5 |
48+
| 1 | 2016-05-02 | 11 |
49+
| 1 | 2017-06-25 | 12 |
50+
| 3 | 2016-03-02 | 0 |
51+
| 3 | 2018-07-03 | 5 |
52+
+-----------+------------+---------------------+
53+
对于 ID 为 1 的玩家,2016-05-02 共玩了 5+6=11 个游戏,2017-06-25 共玩了 5+6+1=12 个游戏。
54+
对于 ID 为 3 的玩家,2018-07-03 共玩了 0+5=5 个游戏。
55+
请注意,对于每个玩家,我们只关心玩家的登录日期。
56+
</pre>
1057

1158
## 解法
1259

@@ -16,8 +63,8 @@ None
1663

1764
### **SQL**
1865

19-
```
20-
select a.player_id, a.event_date, sum(b.games_played) as games_played_so_far from Activity a, Activity b where a.player_id = b.player_id and a.event_date >= b.event_date group by a.player_id, a.event_date
66+
```sql
67+
2168
```
2269

2370
<!-- tabs:end -->

solution/0500-0599/0534.Game Play Analysis III/README_EN.md

+50-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,63 @@
44

55
## Description
66

7-
None
7+
<p>Table:&nbsp;<code>Activity</code></p>
8+
9+
<pre>
10+
+--------------+---------+
11+
| Column Name | Type |
12+
+--------------+---------+
13+
| player_id | int |
14+
| device_id | int |
15+
| event_date | date |
16+
| games_played | int |
17+
+--------------+---------+
18+
(player_id, event_date) is the primary key of this table.
19+
This table shows the activity of players of some game.
20+
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.
21+
</pre>
22+
23+
<p>&nbsp;</p>
24+
25+
<p>Write an SQL query that reports for each player and date, how many games played&nbsp;<strong>so far</strong>&nbsp;by the player. That is, the total number of games played by the player until that date. Check the example for clarity.</p>
26+
27+
<p>The query result format is in the following example:</p>
28+
29+
<pre>
30+
Activity table:
31+
+-----------+-----------+------------+--------------+
32+
| player_id | device_id | event_date | games_played |
33+
+-----------+-----------+------------+--------------+
34+
| 1 | 2 | 2016-03-01 | 5 |
35+
| 1 | 2 | 2016-05-02 | 6 |
36+
| 1 | 3 | 2017-06-25 | 1 |
37+
| 3 | 1 | 2016-03-02 | 0 |
38+
| 3 | 4 | 2018-07-03 | 5 |
39+
+-----------+-----------+------------+--------------+
40+
41+
Result table:
42+
+-----------+------------+---------------------+
43+
| player_id | event_date | games_played_so_far |
44+
+-----------+------------+---------------------+
45+
| 1 | 2016-03-01 | 5 |
46+
| 1 | 2016-05-02 | 11 |
47+
| 1 | 2017-06-25 | 12 |
48+
| 3 | 2016-03-02 | 0 |
49+
| 3 | 2018-07-03 | 5 |
50+
+-----------+------------+---------------------+
51+
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.
52+
For the player with id 3, 0 + 5 = 5 games played by 2018-07-03.
53+
Note that for each player we only care about the days when the player logged in.
54+
</pre>
855

956
## Solutions
1057

1158
<!-- tabs:start -->
1259

1360
### **SQL**
1461

15-
```
16-
select a.player_id, a.event_date, sum(b.games_played) as games_played_so_far from Activity a, Activity b where a.player_id = b.player_id and a.event_date >= b.event_date group by a.player_id, a.event_date
62+
```sql
63+
1764
```
1865

1966
<!-- tabs:end -->

solution/0500-0599/0534.Game Play Analysis III/Solution.sql

-1
This file was deleted.

0 commit comments

Comments
 (0)