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

Browse files
feat: add sql solutions to lc problems: No.0550,0570 (doocs#1185)
* feat: add sql solutions to lc problems: No.0550,0570 * No.0550.Game Play Analysis IV * No.0570.Managers with at Least 5 Direct Reports
1 parent e82d9a4 commit 33b241b

File tree

7 files changed

+107
-13
lines changed

7 files changed

+107
-13
lines changed

‎.github/pull_request_template.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
<!--
44
Below are template for copilot to generate CR message.
55
Please DO NOT modify it.
6-
-->
6+
77
88
### Description
99
1010
copilot:summary
1111
1212
### Explanation of Changes
1313
14-
copilot:walkthrough
14+
copilot:walkthrough
15+
16+
-->

‎.prettierrc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"overrides": [
1414
{
1515
"files": [
16+
"solution/0500-0599/0550.Game Play Analysis IV/Solution.sql",
1617
"solution/0500-0599/0578.Get Highest Answer Rate Question/Solution.sql",
1718
"solution/0600-0699/0610.Triangle Judgement/Solution.sql",
1819
"solution/0600-0699/0618.Students Report By Geography/Solution.sql",

‎solution/0500-0599/0550.Game Play Analysis IV/README.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,34 @@ FROM
7171
AND DATEDIFF(a.event_date, b.event_date) = -1;
7272
```
7373

74+
```sql
75+
# Write your MySQL query statement below
76+
WITH
77+
T AS (
78+
SELECT
79+
player_id,
80+
datediff(
81+
lead(event_date) OVER (
82+
PARTITION BY player_id
83+
ORDER BY event_date
84+
),
85+
event_date
86+
) AS diff,
87+
row_number() OVER (
88+
PARTITION BY player_id
89+
ORDER BY event_date
90+
) AS rk
91+
FROM Activity
92+
)
93+
SELECT
94+
round(
95+
count(DISTINCT if(diff = 1, player_id, NULL)) / count(
96+
DISTINCT player_id
97+
),
98+
2
99+
) AS fraction
100+
FROM T
101+
WHERE rk = 1;
102+
```
103+
74104
<!-- tabs:end -->

‎solution/0500-0599/0550.Game Play Analysis IV/README_EN.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,34 @@ FROM
7373
AND DATEDIFF(a.event_date, b.event_date) = -1;
7474
```
7575

76+
```sql
77+
# Write your MySQL query statement below
78+
WITH
79+
T AS (
80+
SELECT
81+
player_id,
82+
datediff(
83+
lead(event_date) OVER (
84+
PARTITION BY player_id
85+
ORDER BY event_date
86+
),
87+
event_date
88+
) AS diff,
89+
row_number() OVER (
90+
PARTITION BY player_id
91+
ORDER BY event_date
92+
) AS rk
93+
FROM Activity
94+
)
95+
SELECT
96+
round(
97+
count(DISTINCT if(diff = 1, player_id, NULL)) / count(
98+
DISTINCT player_id
99+
),
100+
2
101+
) AS fraction
102+
FROM T
103+
WHERE rk = 1;
104+
```
105+
76106
<!-- tabs:end -->

‎solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,20 @@ FROM
8080
ON e1.id = e2.managerId;
8181
```
8282

83+
```sql
84+
# Write your MySQL query statement below
85+
WITH
86+
T AS (
87+
SELECT
88+
managerId,
89+
count(1) OVER (PARTITION BY managerId) AS cnt
90+
FROM Employee
91+
)
92+
SELECT DISTINCT name
93+
FROM
94+
Employee AS e
95+
JOIN T AS t ON e.id = t.managerId
96+
WHERE cnt >= 5;
97+
```
98+
8399
<!-- tabs:end -->

‎solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,20 @@ FROM
7676
ON e1.id = e2.managerId;
7777
```
7878

79+
```sql
80+
# Write your MySQL query statement below
81+
WITH
82+
T AS (
83+
SELECT
84+
managerId,
85+
count(1) OVER (PARTITION BY managerId) AS cnt
86+
FROM Employee
87+
)
88+
SELECT DISTINCT name
89+
FROM
90+
Employee AS e
91+
JOIN T AS t ON e.id = t.managerId
92+
WHERE cnt >= 5;
93+
```
94+
7995
<!-- tabs:end -->
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# Write your MySQL query statement below
2-
SELECT
3-
name
4-
FROM
5-
Employee AS e1
6-
JOIN (
2+
WITH
3+
T AS (
74
SELECT
8-
managerId
5+
managerId,
6+
count(1) OVER (PARTITION BY managerId) AS cnt
97
FROM Employee
10-
WHERE managerId IS NOT NULL
11-
GROUP BY managerId
12-
HAVING count(1) >= 5
13-
) AS e2
14-
ON e1.id = e2.managerId;
8+
)
9+
SELECT DISTINCT name
10+
FROM
11+
Employee AS e
12+
JOIN T AS t ON e.id = t.managerId
13+
WHERE cnt >= 5;

0 commit comments

Comments
(0)

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