Skip to content

Commit

Permalink
feat: add paid only questions
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed Apr 17, 2021
1 parent 0b84082 commit e4ed7cd
Show file tree
Hide file tree
Showing 675 changed files with 28,405 additions and 16,201 deletions.
48 changes: 45 additions & 3 deletions solution/0500-0599/0511.Game Play Analysis I/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,49 @@

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

None
<p>活动表&nbsp;<code>Activity</code>:</p>

<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| player_id | int |
| device_id | int |
| event_date | date |
| games_played | int |
+--------------+---------+
表的主键是 (player_id, event_date)。
这张表展示了一些游戏玩家在游戏平台上的行为活动。
每行数据记录了一名玩家在退出平台之前,当天使用同一台设备登录平台后打开的游戏的数目(可能是 0 个)。
</pre>

<p>&nbsp;</p>

<p>写一条 SQL&nbsp;查询语句获取每位玩家 <strong>第一次登陆平台的日期</strong>。</p>

<p>查询结果的格式如下所示:</p>

<pre>
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 |
+-----------+-------------+
</pre>

## 解法

Expand All @@ -16,8 +58,8 @@ None

### **SQL**

```
select player_id, min(event_date) as first_login from Activity group by player_id
```sql

```

<!-- tabs:end -->
48 changes: 45 additions & 3 deletions solution/0500-0599/0511.Game Play Analysis I/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,58 @@

## Description

None
<p>Table:&nbsp;<code>Activity</code></p>

<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| player_id | int |
| device_id | int |
| event_date | date |
| games_played | int |
+--------------+---------+
(player_id, event_date) is the primary key of this table.
This table shows the activity of players of some game.
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.
</pre>

<p>&nbsp;</p>

<p>Write an SQL query that reports the&nbsp;<strong>first login date</strong> for each player.</p>

<p>The query result format is in the following example:</p>

<pre>
Activity table:
+-----------+-----------+------------+--------------+
| 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 table:
+-----------+-------------+
| player_id | first_login |
+-----------+-------------+
| 1 | 2016-03-01 |
| 2 | 2017-06-25 |
| 3 | 2016-03-02 |
+-----------+-------------+
</pre>

## Solutions

<!-- tabs:start -->

### **SQL**

```
select player_id, min(event_date) as first_login from Activity group by player_id
```sql

```

<!-- tabs:end -->
1 change: 0 additions & 1 deletion solution/0500-0599/0511.Game Play Analysis I/Solution.sql

This file was deleted.

45 changes: 42 additions & 3 deletions solution/0500-0599/0512.Game Play Analysis II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,46 @@

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

None
<p>Table:&nbsp;<code>Activity</code></p>

<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| player_id | int |
| device_id | int |
| event_date | date |
| games_played | int |
+--------------+---------+
(player_id, event_date) 是这个表的两个主键
这个表显示的是某些游戏玩家的游戏活动情况
每一行是在某天使用某个设备登出之前登录并玩多个游戏(可能为0)的玩家的记录
</pre>

<p>请编写一个 SQL 查询,描述每一个玩家首次登陆的设备名称</p>

<p>查询结果格式在以下示例中:</p>

<pre>
Activity table:
+-----------+-----------+------------+--------------+
| 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 table:
+-----------+-----------+
| player_id | device_id |
+-----------+-----------+
| 1 | 2 |
| 2 | 3 |
| 3 | 1 |
+-----------+-----------+</pre>

## 解法

Expand All @@ -16,8 +55,8 @@ None

### **SQL**

```
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))
```sql

```

<!-- tabs:end -->
47 changes: 44 additions & 3 deletions solution/0500-0599/0512.Game Play Analysis II/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,57 @@

## Description

None
<p>Table:&nbsp;<code>Activity</code></p>

<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| player_id | int |
| device_id | int |
| event_date | date |
| games_played | int |
+--------------+---------+
(player_id, event_date) is the primary key of this table.
This table shows the activity of players of some game.
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.
</pre>

<p>&nbsp;</p>

<p>Write a&nbsp;SQL query that reports&nbsp;the <strong>device</strong>&nbsp;that is first logged in&nbsp;for each player.</p>

<p>The query result format is in the following example:</p>

<pre>
Activity table:
+-----------+-----------+------------+--------------+
| 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 table:
+-----------+-----------+
| player_id | device_id |
+-----------+-----------+
| 1 | 2 |
| 2 | 3 |
| 3 | 1 |
+-----------+-----------+</pre>

## Solutions

<!-- tabs:start -->

### **SQL**

```
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))
```sql

```

<!-- tabs:end -->
1 change: 0 additions & 1 deletion solution/0500-0599/0512.Game Play Analysis II/Solution.sql

This file was deleted.

53 changes: 50 additions & 3 deletions solution/0500-0599/0534.Game Play Analysis III/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,54 @@

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

None
<p>Table:&nbsp;<code>Activity</code></p>

<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| player_id | int |
| device_id | int |
| event_date | date |
| games_played | int |
+--------------+---------+
(player_id,event_date)是此表的主键。
这张表显示了某些游戏的玩家的活动情况。
每一行是一个玩家的记录,他在某一天使用某个设备注销之前登录并玩了很多游戏(可能是 0 )。
</pre>

<p>&nbsp;</p>

<p>编写一个 SQL 查询,同时报告每组玩家和日期,以及玩家到目前为止玩了多少游戏。也就是说,在此日期之前玩家所玩的游戏总数。详细情况请查看示例。</p>

<p>查询结果格式如下所示:</p>

<pre>
Activity table:
+-----------+-----------+------------+--------------+
| player_id | device_id | event_date | games_played |
+-----------+-----------+------------+--------------+
| 1 | 2 | 2016-03-01 | 5 |
| 1 | 2 | 2016-05-02 | 6 |
| 1 | 3 | 2017-06-25 | 1 |
| 3 | 1 | 2016-03-02 | 0 |
| 3 | 4 | 2018-07-03 | 5 |
+-----------+-----------+------------+--------------+

Result table:
+-----------+------------+---------------------+
| player_id | event_date | games_played_so_far |
+-----------+------------+---------------------+
| 1 | 2016-03-01 | 5 |
| 1 | 2016-05-02 | 11 |
| 1 | 2017-06-25 | 12 |
| 3 | 2016-03-02 | 0 |
| 3 | 2018-07-03 | 5 |
+-----------+------------+---------------------+
对于 ID 为 1 的玩家,2016-05-02 共玩了 5+6=11 个游戏,2017-06-25 共玩了 5+6+1=12 个游戏。
对于 ID 为 3 的玩家,2018-07-03 共玩了 0+5=5 个游戏。
请注意,对于每个玩家,我们只关心玩家的登录日期。
</pre>

## 解法

Expand All @@ -16,8 +63,8 @@ None

### **SQL**

```
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
```sql

```

<!-- tabs:end -->
53 changes: 50 additions & 3 deletions solution/0500-0599/0534.Game Play Analysis III/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,63 @@

## Description

None
<p>Table:&nbsp;<code>Activity</code></p>

<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| player_id | int |
| device_id | int |
| event_date | date |
| games_played | int |
+--------------+---------+
(player_id, event_date) is the primary key of this table.
This table shows the activity of players of some game.
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.
</pre>

<p>&nbsp;</p>

<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>

<p>The query result format is in the following example:</p>

<pre>
Activity table:
+-----------+-----------+------------+--------------+
| player_id | device_id | event_date | games_played |
+-----------+-----------+------------+--------------+
| 1 | 2 | 2016-03-01 | 5 |
| 1 | 2 | 2016-05-02 | 6 |
| 1 | 3 | 2017-06-25 | 1 |
| 3 | 1 | 2016-03-02 | 0 |
| 3 | 4 | 2018-07-03 | 5 |
+-----------+-----------+------------+--------------+

Result table:
+-----------+------------+---------------------+
| player_id | event_date | games_played_so_far |
+-----------+------------+---------------------+
| 1 | 2016-03-01 | 5 |
| 1 | 2016-05-02 | 11 |
| 1 | 2017-06-25 | 12 |
| 3 | 2016-03-02 | 0 |
| 3 | 2018-07-03 | 5 |
+-----------+------------+---------------------+
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.
For the player with id 3, 0 + 5 = 5 games played by 2018-07-03.
Note that for each player we only care about the days when the player logged in.
</pre>

## Solutions

<!-- tabs:start -->

### **SQL**

```
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
```sql

```

<!-- tabs:end -->

This file was deleted.

Loading

0 comments on commit e4ed7cd

Please sign in to comment.