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

Browse files
feat: update solutions to lc problems (doocs#1788)
* No.0182.Duplicate Emails * No.1050.Actors and Directors Who Cooperated At Least Three Times * No.1495.Friendly Movies Streamed Last Month * No.1511.Customer Order Frequency * No.1587.Bank Account Summary II * No.1693.Daily Leads and Partners * No.1699.Number of Calls Between Two Persons * No.2562.Find the Array Concatenation Value
1 parent 451ca21 commit 94d498d

File tree

24 files changed

+191
-147
lines changed

24 files changed

+191
-147
lines changed

‎.prettierignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ node_modules/
1616
/solution/0100-0199/0177.Nth Highest Salary/Solution.sql
1717
/solution/1400-1499/1454.Active Users/Solution.sql
1818
/solution/1400-1499/1484.Group Sold Products By The Date/Solution.sql
19-
/solution/1500-1599/1511.Customer Order Frequency/Solution.sql
2019
/solution/1600-1699/1613.Find the Missing IDs/Solution.sql
2120
/solution/1600-1699/1635.Hopper Company Queries I/Solution.sql
2221
/solution/1600-1699/1651.Hopper Company Queries III/Solution.sql

‎.prettierrc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
"solution/1400-1499/1445.Apples & Oranges/Solution.sql",
3535
"solution/1400-1499/1479.Sales by Day of the Week/Solution.sql",
3636
"solution/1500-1599/1501.Countries You Can Safely Invest In/Solution.sql",
37+
"solution/1500-1599/1511.Customer Order Frequency/Solution.sql",
3738
"solution/1500-1599/1555.Bank Account Summary/Solution.sql",
3839
"solution/1600-1699/1667.Fix Names in a Table/Solution.sql",
40+
"solution/1600-1699/1699.Number of Calls Between Two Persons/Solution.sql",
3941
"solution/1700-1799/1777.Product's Price for Each Store/Solution.sql",
4042
"solution/1900-1999/1934.Confirmation Rate/Solution.sql",
4143
"solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql",

‎solution/0100-0199/0182.Duplicate Emails/README.md‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,24 @@ Person 表:
5555

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

58+
**方法一:分组统计**
59+
60+
我们可以使用 `GROUP BY` 语句,按照 `email` 字段进行分组,然后使用 `HAVING` 语句,筛选出现次数大于 1ドル$ 的 `email`
61+
62+
**方法二:自连接**
63+
64+
我们可以使用自连接的方法,将 `Person` 表自身连接一次,然后筛选出 `id` 不同,但 `email` 相同的记录。
65+
5866
<!-- tabs:start -->
5967

6068
### **SQL**
6169

6270
```sql
63-
SELECT Email
71+
# Write your MySQL query statement below
72+
SELECT email
6473
FROM Person
65-
GROUP BY Email
66-
HAVING count(Email) > 1;
74+
GROUP BY 1
75+
HAVING count(1) > 1;
6776
```
6877

6978
```sql

‎solution/0100-0199/0182.Duplicate Emails/README_EN.md‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,24 @@ Person table:
4949

5050
## Solutions
5151

52+
**Solution 1: Group By + Having**
53+
54+
We can use the `GROUP BY` statement to group the data by the `email` field, and then use the `HAVING` statement to filter out the `email` addresses that appear more than once.
55+
56+
**Solution 2: Self-Join**
57+
58+
We can use a self-join to join the `Person` table with itself, and then filter out the records where the `id` is different but the `email` is the same.
59+
5260
<!-- tabs:start -->
5361

5462
### **SQL**
5563

5664
```sql
57-
SELECT Email
65+
# Write your MySQL query statement below
66+
SELECT email
5867
FROM Person
59-
GROUP BY Email
60-
HAVING count(Email) > 1;
68+
GROUP BY 1
69+
HAVING count(1) > 1;
6170
```
6271

6372
```sql
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
SELECT Email
1+
# Write your MySQL query statement below
2+
SELECT email
23
FROM Person
3-
GROUP BY Email
4-
HAVING count(Email) > 1;
4+
GROUP BY 1
5+
HAVING count(1) > 1;

‎solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ ActorDirector 表:
5454

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

57-
**方法一:使用 `GROUP BY` + `HAVING`**
57+
**方法一:分组统计**
5858

59-
我们将 `ActorDirector` 表按照 `actor_id``director_id` 进行分组,然后使用 `HAVING` 过滤出合作次数大于等于 3ドル$ 次的组
59+
我们可以使用 `GROUP BY` 语句,按照 `actor_id``director_id` 字段进行分组,然后使用 `HAVING` 语句,筛选出现次数大于等于 3ドル$ `actor_id``director_id`
6060

6161
<!-- tabs:start -->
6262

‎solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README_EN.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ ActorDirector table:
5353

5454
## Solutions
5555

56-
Use `GROUP BY` & `HAVING`.
56+
**Solution 1: Group By + Having**
57+
58+
We can use the `GROUP BY` statement to group the data by the `actor_id` and `director_id` fields, and then use the `HAVING` statement to filter out the `actor_id` and `director_id` that appear at least three times.
5759

5860
<!-- tabs:start -->
5961

‎solution/1400-1499/1495.Friendly Movies Streamed Last Month/README.md‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,29 +91,24 @@ TVProgram</code> 表:
9191

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

94+
**方法一:等值连接 + 条件筛选**
95+
96+
我们可以先通过等值连接将两张表按照 `content_id` 字段连接起来,然后再通过条件筛选出在 2020ドル$ 年 6ドル$ 月份播放的儿童适宜电影。
97+
9498
<!-- tabs:start -->
9599

96100
### **SQL**
97101

98102
```sql
99-
SELECT DISTINCT
100-
title
103+
# Write your MySQL query statement below
104+
SELECT DISTINCT title
101105
FROM
102-
Content
103-
INNER JOIN TVProgram ONContent.content_id=TVProgram.content_id
106+
TVProgram
107+
JOIN Content USING (content_id)
104108
WHERE
105-
content_type = 'Movies'
109+
date_format(program_date, '%Y%m') = '202006'
106110
AND kids_content = 'Y'
107-
AND program_date BETWEEN '2020年06月01日' AND '2020年06月30日';
108-
```
109-
110-
```sql
111-
SELECT DISTINCT
112-
title
113-
FROM
114-
Content
115-
INNER JOIN TVProgram ON Content.content_id = TVProgram.content_id
116-
WHERE kids_content = 'Y' AND (MONTH(program_date), YEAR(program_date)) = (6, 2020);
111+
AND content_type = 'Movies';
117112
```
118113

119114
<!-- tabs:end -->

‎solution/1400-1499/1495.Friendly Movies Streamed Last Month/README_EN.md‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,22 @@ Content table:
8787

8888
## Solutions
8989

90+
**Solution 1: Equi-Join + Conditional Filtering**
91+
92+
We can first use an equi-join to join the two tables based on the `content_id` field, and then use conditional filtering to select the child-friendly movies that were played in June 2020.
93+
9094
<!-- tabs:start -->
9195

9296
```sql
93-
SELECT DISTINCT
94-
title
97+
# Write your MySQL query statement below
98+
SELECT DISTINCT title
9599
FROM
96-
Content
97-
INNER JOIN TVProgram ONContent.content_id=TVProgram.content_id
100+
TVProgram
101+
JOIN Content USING (content_id)
98102
WHERE
99-
content_type = 'Movies'
103+
date_format(program_date, '%Y%m') = '202006'
100104
AND kids_content = 'Y'
101-
AND program_date BETWEEN '2020年06月01日' AND '2020年06月30日';
102-
```
103-
104-
```sql
105-
SELECT DISTINCT
106-
title
107-
FROM
108-
Content
109-
INNER JOIN TVProgram ON Content.content_id = TVProgram.content_id
110-
WHERE kids_content = 'Y' AND (MONTH(program_date), YEAR(program_date)) = (6, 2020);
105+
AND content_type = 'Movies';
111106
```
112107

113108
<!-- tabs:end -->
Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
SELECT DISTINCT
2-
title
1+
# Write your MySQL query statement below
2+
SELECT DISTINCT title
33
FROM
4-
Content
5-
INNER JOIN TVProgram ONContent.content_id=TVProgram.content_id
4+
TVProgram
5+
JOIN Content USING (content_id)
66
WHERE
7-
content_type = 'Movies'
7+
date_format(program_date, '%Y%m') = '202006'
88
AND kids_content = 'Y'
9-
AND program_date BETWEEN '2020年06月01日' AND '2020年06月30日';
10-
11-
SELECT DISTINCT
12-
title
13-
FROM
14-
Content
15-
INNER JOIN TVProgram ON Content.content_id = TVProgram.content_id
16-
WHERE kids_content = 'Y' AND (MONTH(program_date), YEAR(program_date)) = (6, 2020);
9+
AND content_type = 'Movies';

0 commit comments

Comments
(0)

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