Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e55e434

Browse files
feat: update sql solutions to lc problems: No.0511,0512,0534 (doocs#1182)
* No.0511.Game Play Analysis I * No.0512.Game Play Analysis II * No.0534.Game Play Analysis III
1 parent aa54fe6 commit e55e434

File tree

11 files changed

+80
-22
lines changed

11 files changed

+80
-22
lines changed

‎.github/workflows/black-lint.yml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: black-linter
22

33
on:
4-
pull_request:
5-
branches: [main]
4+
pull_request_target:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
branches:
10+
- main
611

712
jobs:
813
build:

‎.github/workflows/clang-format-lint.yml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: clang-format-linter
22

33
on:
4-
pull_request:
5-
branches: [main]
4+
pull_request_target:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
branches:
10+
- main
611

712
jobs:
813
build:

‎.github/workflows/pr-checker.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ jobs:
6868
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.
6969
7070
<!-- Sticky Pull Request Comment -->
71+
emojis: '+1, laugh'
7172
body-include: '<!-- Sticky Pull Request Comment -->'

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,17 @@ Result 表:
5454

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

57+
**方法一:GROUP BY**
58+
59+
我们可以用 `GROUP BY``player_id` 进行分组,然后取每一组中最小的 `event_date` 作为玩家第一次登录平台的日期。
60+
5761
<!-- tabs:start -->
5862

5963
### **SQL**
6064

6165
```sql
62-
SELECT
63-
player_id,
64-
MIN(event_date) AS first_login
66+
# Write your MySQL query statement below
67+
SELECT player_id, min(event_date) AS first_login
6568
FROM Activity
6669
GROUP BY player_id;
6770
```

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ Activity table:
6060
### **SQL**
6161

6262
```sql
63-
SELECT
64-
player_id,
65-
MIN(event_date) AS first_login
63+
# Write your MySQL query statement below
64+
SELECT player_id, min(event_date) AS first_login
6665
FROM Activity
6766
GROUP BY player_id;
6867
```
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
SELECT
2-
player_id,
3-
MIN(event_date) AS first_login
1+
# Write your MySQL query statement below
2+
SELECT player_id, min(event_date) AS first_login
43
FROM Activity
54
GROUP BY player_id;

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ Result table:
5151

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

54+
**方法一:子查询**
55+
56+
我们可以使用 `GROUP BY``MIN` 函数来找到每个玩家的第一次登录日期,然后使用联合键子查询来找到每个玩家的第一次登录设备。
57+
58+
**方法二:窗口函数**
59+
60+
我们可以使用窗口函数 `rank()`,它可以为每个玩家的每个登录日期分配一个排名,然后我们可以选择排名为 1ドル$ 的行。
61+
5462
<!-- tabs:start -->
5563

5664
### **SQL**
@@ -71,4 +79,21 @@ WHERE
7179
);
7280
```
7381

82+
```sql
83+
# Write your MySQL query statement below
84+
WITH
85+
T AS (
86+
SELECT
87+
*,
88+
rank() OVER (
89+
PARTITION BY player_id
90+
ORDER BY event_date
91+
) AS rk
92+
FROM Activity
93+
)
94+
SELECT player_id, device_id
95+
FROM T
96+
WHERE rk = 1;
97+
```
98+
7499
<!-- tabs:end -->

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,21 @@ WHERE
7575
);
7676
```
7777

78+
```sql
79+
# Write your MySQL query statement below
80+
WITH
81+
T AS (
82+
SELECT
83+
*,
84+
rank() OVER (
85+
PARTITION BY player_id
86+
ORDER BY event_date
87+
) AS rk
88+
FROM Activity
89+
)
90+
SELECT player_id, device_id
91+
FROM T
92+
WHERE rk = 1;
93+
```
94+
7895
<!-- tabs:end -->

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,24 @@ Result table:
5959

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

62+
**方法一:SUM() OVER() 窗口函数**
63+
64+
我们可以使用 `SUM() OVER()` 窗口函数来计算每个玩家到目前为止玩了多少游戏。在 `OVER()` 子句中,我们使用 `PARTITION BY` 子句将玩家分组,然后使用 `ORDER BY` 子句按日期排序。
65+
6266
<!-- tabs:start -->
6367

6468
### **SQL**
6569

6670
```sql
71+
# Write your MySQL query statement below
6772
SELECT
6873
player_id,
6974
event_date,
70-
SUM(games_played) OVER (
75+
sum(games_played) OVER (
7176
PARTITION BY player_id
7277
ORDER BY event_date
7378
) AS games_played_so_far
74-
FROM Activity
75-
ORDER BY 1, 2;
79+
FROM Activity;
7680
```
7781

7882
<!-- tabs:end -->

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ Note that for each player we only care about the days when the player logged in.
6666
### **SQL**
6767

6868
```sql
69+
# Write your MySQL query statement below
6970
SELECT
7071
player_id,
7172
event_date,
72-
SUM(games_played) OVER (
73+
sum(games_played) OVER (
7374
PARTITION BY player_id
7475
ORDER BY event_date
7576
) AS games_played_so_far
76-
FROM Activity
77-
ORDER BY 1, 2;
77+
FROM Activity;
7878
```
7979

8080
<!-- tabs:end -->

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /