LetCode-MySql删除重复的电子邮箱
生活随笔
收集整理的這篇文章主要介紹了
LetCode-MySql删除重复的电子邮箱
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
解法(1):思路為先查詢出查詢出重復的ID并且取最小值
select min(Id) Id,Email from Person group by Email或者
Select min(Id) as Id,distinct Email from Person然后刪除不在ID為此里面的值
delete from Person where Id not in(select Id from ( select min(Id) Id,Email from Person group by Email)t)解法(2):使用 查詢出Email相等ID不是最小的
select B.Id as Id from Person as A,Person as B where A.Id<B.Id and A.Email=B.Email然后刪除查詢出來的結果
delete from Person where Id in(select Id from(select B.Id as Id from Person as A,Person as B where A.Id<B.Id and A.Email=B.Email) t)總結
以上是生活随笔為你收集整理的LetCode-MySql删除重复的电子邮箱的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Web项目练习总结(错误校正篇)
- 下一篇: 适配器模式的应用