力扣题目:查找重复的电子邮箱

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

+----+---------+
| Id | Email   |
+----+---------+
| 1  | a@b.com |
| 2  | c@d.com |
| 3  | a@b.com |
+----+---------+

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

+---------+
| Email   |
+---------+
| a@b.com |
+---------+

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

我写的SQL:

select Email from (select count(Email) as c,Email from Person group by Email) T where T.c>1;

由于having可以进行聚合函数的判断,SQL可以更简洁

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

 

posted on 2021-02-10 11:51  周文豪  阅读(413)  评论(0编辑  收藏  举报