182. 查找重复的电子邮箱 + group by + having

182. 查找重复的电子邮箱

LeetCode_MySql_182

题目描述

182. 查找重复的电子邮箱 + group by + having

方法一:使用笛卡尔积

# Write your MySQL query statement below
select distinct t1.Email
from 
     Person t1,
     Person t2
where 
     t1.Id != t2.Id
     and t1.Email = t2.Email;

方法二:使用group by 和临时表

select Email
from
(
    select Email, count(Email) as num
    from Person
    group by Email
) as temp
where num > 1;

方法三:使用group by + having

select Email
from Person
group by Email
having count(Email) > 1;
上一篇:Java 手机号码格式化为182****5716


下一篇:182. 删除数字