删除重复邮箱
作者:互联网
删除重复的邮箱数据
输入:
Person 表:
+----+------------------+
| id | email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
| 3 | john@example.com |
+----+------------------+
输出:
+----+------------------+
| id | email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
+----+------------------+
解释: john@example.com重复两次。我们保留最小的Id = 1。
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/delete-duplicate-emails
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
解法1.
delete u from Person u , Person v where v.id < u.id and u.email = v.email 1.使用delete 配合关联查询时,需要在delete from 中 输入删除表别名 !! 解法2.DELETE from Person Where Id not in ( Select Id From( Select MIN(Id) as id From Person Group by Email ) t ) 1. group By email 取id 最小的那个email id , 然后用 not exists 或者 not in
标签:删除,重复,example,Person,+----+------------------+,邮箱,Id,com,id 来源: https://www.cnblogs.com/yubaluquba/p/16415733.html