[LeetCode]Duplicate Emails

题目描述:

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.

题目大意:

编写一个SQL查询从Person表中找出所有重复的邮箱地址。

例如,上表的查询结果应该返回a@b.com

所有的邮箱地址均为小写字母。

解题思路:

使用GROUP BY和HAVING即可

SQL语句:

# Write your MySQL query statement below
SELECT Email FROM Person GROUP BY Email HAVING COUNT(*) > 1

 

本文链接:http://bookshadow.com/weblog/2015/01/17/leetcode-duplicate-emails/
请尊重作者的劳动成果,转载请注明出处!书影博客保留对文章的所有权利。

如果您喜欢这篇博文,欢迎您捐赠书影博客: ,查看支付宝二维码

Pingbacks已关闭。

暂无评论

张贴您的评论