zoukankan      html  css  js  c++  java
  • mysql--查找重复的电子邮件

    解法一:(创建临时表当做子表来处理)

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

      

    解法二:(where好像只能用于原有数据表字段,聚合函数生成的字段无法配合使用)

    select Email from Person group by Email having count(Email) > 1;
    

      

    解法三:

    select distinct a.Email from Person a, Person b where a.Email = b.Email and a.Id != b.Id 
    

      

     补充:

    1、where后面不能跟聚合函数

    2、group by 非聚合函数列  having 可以是聚合函数

    3、where 子句的作用是在对查询结果进行分组前,将不符合where条件的行去掉,即在分组之前过滤数据,条件中不能包含聚组函数,使用where条件显示特定的行。

    4、having 子句的作用是筛选满足条件的组,即在分组之后过滤数据,条件中经常包含聚组函数,使用having 条件显示特定的组,也可以使用多个分组标准进行分组。

  • 相关阅读:
    技术博客之Saju M
    Dajax 的安装以及详细使用
    当我感觉厌倦的时候
    2014年3月22日 星期日
    windows 7远程桌面访问 ubuntu12.04
    promise的用法
    for循环中匿名同步
    开启Group Work Site功能
    Jquery根据属性模糊查询节点
    设置用户字段
  • 原文地址:https://www.cnblogs.com/vegetableDD/p/11634913.html
Copyright © 2011-2022 走看看