Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/black-lint.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: black-linter

on:
pull_request:
branches: [main]
pull_request_target:
types:
- opened
- edited
- synchronize
branches:
- main

jobs:
build:
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/clang-format-lint.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: clang-format-linter

on:
pull_request:
branches: [main]
pull_request_target:
types:
- opened
- edited
- synchronize
branches:
- main

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ jobs:
In addition, the coding style (such as the naming of variables and functions) should be as consistent as possible with the existing code in the project.

<!-- Sticky Pull Request Comment -->
emojis: '+1, laugh'
body-include: '<!-- Sticky Pull Request Comment -->'
9 changes: 6 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 @@ -54,14 +54,17 @@ Result 表:

<!-- 这里可写通用的实现逻辑 -->

**方法一:GROUP BY**

我们可以用 `GROUP BY` 对 `player_id` 进行分组,然后取每一组中最小的 `event_date` 作为玩家第一次登录平台的日期。

<!-- tabs:start -->

### **SQL**

```sql
SELECT
player_id,
MIN(event_date) AS first_login
# Write your MySQL query statement below
SELECT player_id, min(event_date) AS first_login
FROM Activity
GROUP BY player_id;
```
Expand Down
5 changes: 2 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 @@ -60,9 +60,8 @@ Activity table:
### **SQL**

```sql
SELECT
player_id,
MIN(event_date) AS first_login
# Write your MySQL query statement below
SELECT player_id, min(event_date) AS first_login
FROM Activity
GROUP BY player_id;
```
Expand Down
5 changes: 2 additions & 3 deletions solution/0500-0599/0511.Game Play Analysis I/Solution.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
SELECT
player_id,
MIN(event_date) AS first_login
# Write your MySQL query statement below
SELECT player_id, min(event_date) AS first_login
FROM Activity
GROUP BY player_id;
25 changes: 25 additions & 0 deletions solution/0500-0599/0512.Game Play Analysis II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ Result table:

<!-- 这里可写通用的实现逻辑 -->

**方法一:子查询**

我们可以使用 `GROUP BY` 和 `MIN` 函数来找到每个玩家的第一次登录日期,然后使用联合键子查询来找到每个玩家的第一次登录设备。

**方法二:窗口函数**

我们可以使用窗口函数 `rank()`,它可以为每个玩家的每个登录日期分配一个排名,然后我们可以选择排名为 $1$ 的行。

<!-- tabs:start -->

### **SQL**
Expand All @@ -71,4 +79,21 @@ WHERE
);
```

```sql
# Write your MySQL query statement below
WITH
T AS (
SELECT
*,
rank() OVER (
PARTITION BY player_id
ORDER BY event_date
) AS rk
FROM Activity
)
SELECT player_id, device_id
FROM T
WHERE rk = 1;
```

<!-- tabs:end -->
17 changes: 17 additions & 0 deletions solution/0500-0599/0512.Game Play Analysis II/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,21 @@ WHERE
);
```

```sql
# Write your MySQL query statement below
WITH
T AS (
SELECT
*,
rank() OVER (
PARTITION BY player_id
ORDER BY event_date
) AS rk
FROM Activity
)
SELECT player_id, device_id
FROM T
WHERE rk = 1;
```

<!-- tabs:end -->
10 changes: 7 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 @@ -59,20 +59,24 @@ Result table:

<!-- 这里可写通用的实现逻辑 -->

**方法一:SUM() OVER() 窗口函数**

我们可以使用 `SUM() OVER()` 窗口函数来计算每个玩家到目前为止玩了多少游戏。在 `OVER()` 子句中,我们使用 `PARTITION BY` 子句将玩家分组,然后使用 `ORDER BY` 子句按日期排序。

<!-- tabs:start -->

### **SQL**

```sql
# Write your MySQL query statement below
SELECT
player_id,
event_date,
SUM(games_played) OVER (
sum(games_played) OVER (
PARTITION BY player_id
ORDER BY event_date
) AS games_played_so_far
FROM Activity
ORDER BY 1, 2;
FROM Activity;
```

<!-- tabs:end -->
6 changes: 3 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 @@ -66,15 +66,15 @@ Note that for each player we only care about the days when the player logged in.
### **SQL**

```sql
# Write your MySQL query statement below
SELECT
player_id,
event_date,
SUM(games_played) OVER (
sum(games_played) OVER (
PARTITION BY player_id
ORDER BY event_date
) AS games_played_so_far
FROM Activity
ORDER BY 1, 2;
FROM Activity;
```

<!-- tabs:end -->
6 changes: 3 additions & 3 deletions solution/0500-0599/0534.Game Play Analysis III/Solution.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Write your MySQL query statement below
SELECT
player_id,
event_date,
SUM(games_played) OVER (
sum(games_played) OVER (
PARTITION BY player_id
ORDER BY event_date
) AS games_played_so_far
FROM Activity
ORDER BY 1, 2;
FROM Activity;