题目
Write a SQL query to find all duplicate emails in a table named Person.
+—-+———+
| Id | Email |
+—-+———+
| 1 | a@b.com |
| 2 | c@d.com |
| 3 | a@b.com |
+—-+———+
For example, your query should return the following for the above table:
+———+
| Email |
+———+
| a@b.com |
+———+
Note: All emails are in lowercase.
题目来源:https://leetcode.com/problems/duplicate-emails/
代码
有哪些邮箱重复?把邮箱显示出来。
# Write your MySQL query statement below
select Email from Person group by Email having count(Id) > 1;
注:MySQL中having关键字是在数据分组之后进行过滤选择分组,而where是在分组之前用来选择记录。where排除的记录不再包括在分组中。