您的位置:首页 > 数据库 > MySQL

【MySQL】【leetcode】 Duplicate Emails解题报告

2015-10-20 16:49 661 查看

题目

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排除的记录不再包括在分组中。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据库 mysql leetcode