您的位置:首页 > 大数据 > 人工智能

leetcode182-Duplicate Emails(找出出现重复的数据)

2016-04-08 11:31 501 查看
问题描述:

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 |
+---------+


问题求解:

1、distinct

select distinct p1.email from Person p1, Person p2
where p1.email = p2.email and p1.Id != p2.Id


2、group by & having

select email from Person
group by email
having count(*)>1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: