1 题目
2 MySQL
2.1 方法一(groupby……having)
不能把count判断放在where中
因为执行顺序是 from、where、groupby、having、select
count 必须在 groupby 之后执行
select Email
from Person
group by Email
having count(Email) > 1;
2.2 方法二(子表)
select Email
from(
select Email, count(Email) as num
from Person
group by Email
) as subTable
where num > 1;
3 如何查找重复数据
3.1 方法一:groupby + having count()
select 列名
from 表名
group by 列名
having count(列名) > n;
3.2 方法二:from辅助表 + where
select 姓名 from
(
select 姓名, count(姓名) as 计数
from 学生表
group by 姓名
) as 辅助表
where 计数 > 1;