/* 删除重复 */
if exists (select * from master.dbo.sysdatabases where name='LeetCode')
begin
use master
drop database LeetCode
select 'dd'
end
create database LeetCode
use LeetCode
go
if exists (select * from sys.objects where name='Person')
drop table Person
create table Person
(
Id int identity primary key,
Email varchar(30)
)
insert into Person values
('john@example.com'),('bob@example.com'),('john@example.com'),
('chen@example.com'),('chen@example.com')
go
delete from Person
where Id in
(
select p1.Id
from Person p1, Person p2
where p1.Email=p2.Email and p1.Id>p2.Id
)
go
select *
from Person