LeetCode(182):查找重复的电子邮箱 Duplicate Emails(SQL)

2019.12.8 LeetCode 从零单刷个人笔记整理(持续更新)

github:https://github.com/ChopinXBP/LeetCode-Babel

传送门:查找重复的电子邮箱

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

示例:

+----+---------+
| Id | Email   |
+----+---------+
| 1  | [email protected] |
| 2  | [email protected] |
| 3  | [email protected] |
+----+---------+

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

+---------+
| Email   |
+---------+
| [email protected] |
+---------+

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



SELECT a.Email
FROM (
    SELECT Email, COUNT(Email) 'num'
    FROM Person
    GROUP BY Email
) a
WHERE a.num > 1;

select Email
from Person
group by Email
having count(Email) > 1;



#Coding一小时,Copying一秒钟。留个言点个赞呗,谢谢你#

发布了246 篇原创文章 · 获赞 316 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_20304723/article/details/103443493