## LeetCode：Delete Duplicate Emails - 删除重复的邮箱数据 原

北风其凉

1、题目名称

Delete Duplicate Emails（删除重复的邮箱数据）

2、题目地址

https://leetcode.com/problems/delete-duplicate-emails/

3、题目内容

+----+------------------+
| Id | Email            |
+----+------------------+
| 1  | john@example.com |
| 2  | bob@example.com  |
| 3  | john@example.com |
+----+------------------+
Id is the primary key column for this table.

+----+------------------+
| Id | Email            |
+----+------------------+
| 1  | john@example.com |
| 2  | bob@example.com  |
+----+------------------+

4、初始化数据库脚本

-- 执行脚本前必须建立名为LEETCODE的DATABASE
USE LEETCODE;

DROP TABLE IF EXISTS Person;
CREATE TABLE Person (
Id INT NOT NULL PRIMARY KEY,
Email VARCHAR(50)
);

-- INSERT INTO Person (Id, Email) VALUES (1, 'john@example.com');
-- INSERT INTO Person (Id, Email) VALUES (2, 'bob@example.com');
-- INSERT INTO Person (Id, Email) VALUES (3, 'john@example.com');
INSERT INTO Person (Id, Email) VALUES (1, 'tsybius@example.com');
INSERT INTO Person (Id, Email) VALUES (2, 'tsybius@example.com');

5、解题SQL1

DELETE P2 FROM Person AS P1, Person AS P2
WHERE  P1.Email = P2.Email AND
P1.Id < P2.Id;

6、解题SQL2

DELETE FROM Person
WHERE  Id NOT IN (SELECT MIN(ID) MIN_ID
FROM   Person
GROUP  BY Email)

ERROR 1093 (HY000): You can't specify target table 'Person' for update in FROM clause

DELETE FROM Person
WHERE  Id NOT IN (SELECT TMP.MIN_ID
FROM   (SELECT MIN(ID) MIN_ID
FROM   Person
GROUP  BY Email) TMP);

END

### 北风其凉

【sql】删除重复的邮件 Delete Duplicate Emails

2017/11/13
0
0
LeetCode：Duplicate Emails - 重复出现的Email

1、题目名称 Duplicate Emails（重复出现的Email） 2、题目地址 https://leetcode.com/problems/duplicate-emails/ 3、题目内容 有一个数据表包括Id和Email两列，找出数据表内Email列内容重复...

2015/08/16
0
0
【sql】统计重复出现的邮箱 Duplicate Emails

2017/11/09
0
0
LeetCode 721. Accounts Merge

likewind1993
2017/11/17
0
0
Mysql中Insert into xxx on duplicate key update问题

2017/11/19
0
0

typescript 接口 函数类型 可索引类型

lilugirl

3
0
Oracle SQL语法实例合集

LoSingSang

2
0

https://serverfault.com/questions/628610/increasing-nproc-for-processes-launched-by-systemd-on-centos-7 要在systemd的配置里加才行...

helloclia

2
0

3
0