[Leetcode] [Database] Duplicate Emails解题思路

来源:互联网 发布:php for循环乘法口诀表 编辑:程序博客网 时间:2024/09/21 13:50

重复邮件

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

题目意思: 选出数据库中重复出现的数据


解题思路: 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
0 0
原创粉丝点击