leetcode 196. Delete Duplicate Emails

发布时间:2017-6-29 10:35:10编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"leetcode 196. Delete Duplicate Emails",主要涉及到leetcode 196. Delete Duplicate Emails方面的内容,对于leetcode 196. Delete Duplicate Emails感兴趣的同学可以参考一下。

题目:196. Delete Duplicate Emails
1。建表

create table Person(
    Id int not null auto_increment,
    Email varchar(30) default null,
    primary key (Id)
)

insert into Person(Email) values ('john@example.com');
insert into Person(Email) values ('john@example.com');
insert into Person(Email) values ('bob@example.com');
insert into Person(Email) values ('tom@example.com');
insert into Person(Email) values ('tom@example.com');
insert into Person(Email) values ('tom@example.com');
select * from Person;

2。解答:

DELETE FROM Person
WHERE Id NOT IN (
  SELECT * FROM (
    SELECT Min(Id)
    FROM Person
    GROUP BY Email
  ) tmp
)

delete from Person
where  Id not in (
    select Id from 
    (select min(Id) as Id 
     from Person 
     group by Email
    ) tmp
);

delete from Person 
where Id not in (
select Id from (
    select min(Id) as Id from Person
    group by Email
)as tmp
)

DELETE p1
FROM Person p1, Person p2
WHERE p1.Email = p2.Email AND
p1.Id > p2.Id;


上一篇:linux的popen函数使用
下一篇:怎么给linux加环境变量

相关文章

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款