查找重复的电子邮箱

编写一个 SQL 查询,查找 Person 表中所有重复的电子邮箱。

示例:

Id Email
1 [email protected]
2 [email protected]
3 [email protected]

根据以上输入,你的查询应返回以下结果:

Email
[email protected]

说明:所有电子邮箱都是小写字母。
解题思路:

首先,还是自表连接,通过两张表的id和email名字来确定是否是同一邮件

最后去除重复的email

select distinct p1.Email as Email 
from person p1, person p2
where p1.Email=p2.Email and p1.id!=p2.id

还是比较简单的

发布了34 篇原创文章 · 获赞 21 · 访问量 1912

猜你喜欢

转载自blog.csdn.net/qq_44156131/article/details/104050988