重复邮件
Write a SQL query to find all duplicate emails in a table named Person.
Id 1 a@b.com 2 c@d.com 3 a@b.com For example, your query should return the following for the above table:
a@b.com
题目意思: 选出数据库中重复出现的数据
解题思路: count一下大于1就行
select Email from Person group by 1 having count(1)>1;
尝试过相似的代码, 不过不能通过, 个人觉得意思是一样的, 可能空值不对吧. 代码如下:
select case when p.c>1 then p.Email else null end as email from (select Email, count(*) c from Person group by 1) p