auto commit

This commit is contained in:
CyC2018 2019-12-11 00:26:43 +08:00
parent 3b3fac2878
commit 612d266233
2 changed files with 32 additions and 14 deletions

View File

@ -230,7 +230,7 @@ https://leetcode.com/problems/classes-more-than-5-students/description/
## Solution
class 列进行分组之后再使用 count 汇总函数统计数量统计之后使用 having 进行过滤
class 列进行分组之后再使用 count 汇总函数统计每个分组的记录个数之后使用 HAVING 进行筛选HAVING 针对分组进行筛选 WHERE 针对每个记录进行筛选
```sql
SELECT
@ -293,7 +293,7 @@ https://leetcode.com/problems/duplicate-emails/description/
## Solution
Email 进行分组如果相同 Email 的数量大于等于 2则表示该 Email 重复
Email 进行分组如果并使用 COUNT 进行计数统计结果大于等于 2 的表示 Email 重复
```sql
SELECT
@ -354,7 +354,7 @@ https://leetcode.com/problems/delete-duplicate-emails/description/
只保留相同 Email Id 最小的那一个然后删除其它的
连接
连接查询
```sql
DELETE p1
@ -373,7 +373,14 @@ DELETE
FROM
Person
WHERE
id NOT IN ( SELECT id FROM ( SELECT min( id ) AS id FROM Person GROUP BY email ) AS m );
id NOT IN (
SELECT id
FROM (
SELECT min( id ) AS id
FROM Person
GROUP BY email
) AS m
);
```
应该注意的是上述解法额外嵌套了一个 SELECT 语句如果不这么做会出现错误You can't specify target table 'Person' for update in FROM clause以下演示了这种错误解法
@ -383,7 +390,11 @@ DELETE
FROM
Person
WHERE
id NOT IN ( SELECT min( id ) AS id FROM Person GROUP BY email );
id NOT IN (
SELECT min( id ) AS id
FROM Person
GROUP BY email
);
```
参考[pMySQL Error 1093 - Can't specify target table for update in FROM clause](https://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause)
@ -392,8 +403,6 @@ WHERE
182 相同
# 175. Combine Two Tables
https://leetcode.com/problems/combine-two-tables/description/

View File

@ -230,7 +230,7 @@ https://leetcode.com/problems/classes-more-than-5-students/description/
## Solution
class 列进行分组之后再使用 count 汇总函数统计数量统计之后使用 having 进行过滤
class 列进行分组之后再使用 count 汇总函数统计每个分组的记录个数之后使用 HAVING 进行筛选HAVING 针对分组进行筛选 WHERE 针对每个记录进行筛选
```sql
SELECT
@ -293,7 +293,7 @@ https://leetcode.com/problems/duplicate-emails/description/
## Solution
Email 进行分组如果相同 Email 的数量大于等于 2则表示该 Email 重复
Email 进行分组如果并使用 COUNT 进行计数统计结果大于等于 2 的表示 Email 重复
```sql
SELECT
@ -354,7 +354,7 @@ https://leetcode.com/problems/delete-duplicate-emails/description/
只保留相同 Email Id 最小的那一个然后删除其它的
连接
连接查询
```sql
DELETE p1
@ -373,7 +373,14 @@ DELETE
FROM
Person
WHERE
id NOT IN ( SELECT id FROM ( SELECT min( id ) AS id FROM Person GROUP BY email ) AS m );
id NOT IN (
SELECT id
FROM (
SELECT min( id ) AS id
FROM Person
GROUP BY email
) AS m
);
```
应该注意的是上述解法额外嵌套了一个 SELECT 语句如果不这么做会出现错误You can't specify target table 'Person' for update in FROM clause以下演示了这种错误解法
@ -383,7 +390,11 @@ DELETE
FROM
Person
WHERE
id NOT IN ( SELECT min( id ) AS id FROM Person GROUP BY email );
id NOT IN (
SELECT min( id ) AS id
FROM Person
GROUP BY email
);
```
参考[pMySQL Error 1093 - Can't specify target table for update in FROM clause](https://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause)
@ -392,8 +403,6 @@ WHERE
182 相同
# 175. Combine Two Tables
https://leetcode.com/problems/combine-two-tables/description/