We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
查找 person 表中所有重复的电子邮箱
person
create table person ( id int, email varchar(255) ); insert into person values(1, '[email protected]'), (2, '[email protected]'), (3, '[email protected]');
select email from person group by email having count(email) > 1;
通过 group by 对 email 分组,在使用 having 将重复的 email 筛选出来。
group by
email
having
select t.email from ( select email, count(email) num from person group by email ) t where t.num > 1;
将 email 分组后计算出相同 email 的数量作为临时表,筛选出 num > 1 的邮箱
num > 1
with temp as ( select email, count(email) num from person group by email ) select email from temp where num > 1;
使用 with 建立临时表,和方法二一样
with
select distinct person.email from person left join person temp on person.email = temp.email where person.id != temp.id;
使用 left join 自连,连接条件是 person.eamil = temp.email 并且通过 where 把 person.id != temp.id筛选出来,最后再通过 distinct 去重
left join
person.eamil = temp.email
where
person.id != temp.id
distinct
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目
查找
person
表中所有重复的电子邮箱SQL:方法一
解析
通过
group by
对email
分组,在使用having
将重复的email
筛选出来。SQL:方法二
解析
将
email
分组后计算出相同email
的数量作为临时表,筛选出num > 1
的邮箱SQL:方法三
解析
使用
with
建立临时表,和方法二一样SQL:方法四
解析
使用
left join
自连,连接条件是person.eamil = temp.email
并且通过where
把person.id != temp.id
筛选出来,最后再通过distinct
去重The text was updated successfully, but these errors were encountered: