File tree Expand file tree Collapse file tree 11 files changed +80
-22
lines changed
0511.Game Play Analysis I
0512.Game Play Analysis II
0534.Game Play Analysis III Expand file tree Collapse file tree 11 files changed +80
-22
lines changed Original file line number Diff line number Diff line change 1
1
name : black-linter
2
2
3
3
on :
4
- pull_request :
5
- branches : [main]
4
+ pull_request_target :
5
+ types :
6
+ - opened
7
+ - edited
8
+ - synchronize
9
+ branches :
10
+ - main
6
11
7
12
jobs :
8
13
build :
Original file line number Diff line number Diff line change 1
1
name : clang-format-linter
2
2
3
3
on :
4
- pull_request :
5
- branches : [main]
4
+ pull_request_target :
5
+ types :
6
+ - opened
7
+ - edited
8
+ - synchronize
9
+ branches :
10
+ - main
6
11
7
12
jobs :
8
13
build :
Original file line number Diff line number Diff line change 68
68
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.
69
69
70
70
<!-- Sticky Pull Request Comment -->
71
+ emojis : ' +1, laugh'
71
72
body-include : ' <!-- Sticky Pull Request Comment -->'
Original file line number Diff line number Diff line change @@ -54,14 +54,17 @@ Result 表:
54
54
55
55
<!-- 这里可写通用的实现逻辑 -->
56
56
57
+ ** 方法一:GROUP BY**
58
+
59
+ 我们可以用 ` GROUP BY ` 对 ` player_id ` 进行分组,然后取每一组中最小的 ` event_date ` 作为玩家第一次登录平台的日期。
60
+
57
61
<!-- tabs:start -->
58
62
59
63
### ** SQL**
60
64
61
65
``` 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
65
68
FROM Activity
66
69
GROUP BY player_id;
67
70
```
Original file line number Diff line number Diff line change @@ -60,9 +60,8 @@ Activity table:
60
60
### ** SQL**
61
61
62
62
``` 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
66
65
FROM Activity
67
66
GROUP BY player_id;
68
67
```
Original file line number Diff line number Diff line change 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
4
3
FROM Activity
5
4
GROUP BY player_id;
Original file line number Diff line number Diff line change @@ -51,6 +51,14 @@ Result table:
51
51
52
52
<!-- 这里可写通用的实现逻辑 -->
53
53
54
+ ** 方法一:子查询**
55
+
56
+ 我们可以使用 ` GROUP BY ` 和 ` MIN ` 函数来找到每个玩家的第一次登录日期,然后使用联合键子查询来找到每个玩家的第一次登录设备。
57
+
58
+ ** 方法二:窗口函数**
59
+
60
+ 我们可以使用窗口函数 ` rank() ` ,它可以为每个玩家的每个登录日期分配一个排名,然后我们可以选择排名为 $1$ 的行。
61
+
54
62
<!-- tabs:start -->
55
63
56
64
### ** SQL**
71
79
);
72
80
```
73
81
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
+
74
99
<!-- tabs:end -->
Original file line number Diff line number Diff line change 75
75
);
76
76
```
77
77
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
+
78
95
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -59,20 +59,24 @@ Result table:
59
59
60
60
<!-- 这里可写通用的实现逻辑 -->
61
61
62
+ ** 方法一:SUM() OVER() 窗口函数**
63
+
64
+ 我们可以使用 ` SUM() OVER() ` 窗口函数来计算每个玩家到目前为止玩了多少游戏。在 ` OVER() ` 子句中,我们使用 ` PARTITION BY ` 子句将玩家分组,然后使用 ` ORDER BY ` 子句按日期排序。
65
+
62
66
<!-- tabs:start -->
63
67
64
68
### ** SQL**
65
69
66
70
``` sql
71
+ # Write your MySQL query statement below
67
72
SELECT
68
73
player_id,
69
74
event_date,
70
- SUM (games_played) OVER (
75
+ sum (games_played) OVER (
71
76
PARTITION BY player_id
72
77
ORDER BY event_date
73
78
) AS games_played_so_far
74
- FROM Activity
75
- ORDER BY 1 , 2 ;
79
+ FROM Activity;
76
80
```
77
81
78
82
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -66,15 +66,15 @@ Note that for each player we only care about the days when the player logged in.
66
66
### ** SQL**
67
67
68
68
``` sql
69
+ # Write your MySQL query statement below
69
70
SELECT
70
71
player_id,
71
72
event_date,
72
- SUM (games_played) OVER (
73
+ sum (games_played) OVER (
73
74
PARTITION BY player_id
74
75
ORDER BY event_date
75
76
) AS games_played_so_far
76
- FROM Activity
77
- ORDER BY 1 , 2 ;
77
+ FROM Activity;
78
78
```
79
79
80
80
<!-- tabs:end -->
You can’t perform that action at this time.
0 commit comments