查找重复的邮箱

编写一个 SQL 查询,查找 Person 表中所有重复的电子邮箱。     
  示例:
    
    +----+---------+
    | Id | Email   |
    +----+---------+
    | 1  | a@b.com |
    | 2  | c@d.com |
    | 3  | a@b.com |
    +----+---------+
    根据以上输入,你的查询应返回以下结果:
    
    +---------+
    | Email   |
    +---------+
    | a@b.com |
    +---------+
    说明:所有电子邮箱都是小写字母。
`解题思路`

1 嵌套表查询
    `select Email from (
     select Email, count(Email) as a
     from Person
     group by Email) as b
     where a>1`
2 group by ... having
 `select Email
         from Person
         group by Email
         having count(Email) > 1;`
  • where 子句的作用是在对查询结果进行分组前,将不符合where条件的行去掉,即在分组之前过滤数据,where条件中不能包含聚组函数,使用where条件过滤出特定的行。
  • having 子句的作用是筛选满足条件的组,即在分组之后过滤数据,条件中经常包含聚组函数,使用having 条件过滤出特定的组,也可以使用多个分组标准进行分组。
posted @ 2020-03-20 10:15  花花妹子。  阅读(237)  评论(0编辑  收藏  举报