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

182. 查找重复的电子邮箱

LeetCode_MySql_182

题目描述

方法一:使用笛卡尔积

# 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;
posted @ 2021-03-02 18:28  Garrett_Wale  阅读(85)  评论(0编辑  收藏  举报