题目
题目难度:简单
编写一个 SQL 查询,来删除 Person 表中所有重复的电子邮箱,重复的邮箱里只保留 Id 最小 的那个。
Id |
Email |
1 |
aaa@qq.com |
2 |
aaa@qq.com |
3 |
aaa@qq.com |
例如,在运行你的查询语句之后,上面的 Person 表应返回以下几行:
Id |
Email |
1 |
aaa@qq.com |
2 |
aaa@qq.com |
解题
代码
DELETE p1
FROM Person as p1 , person as p2
where p1.Email=p2.Email and p1.Id>p2.Id