日期:2014-05-17 浏览次数:20538 次
create table Test_del
(
id int,
name varchar(2),
aid int
)
insert into test_del
select 1 ,'a', 1 union all
select 2 ,'a', 1 union all
select 3 ,'ab', 1 union all
select 4 ,'b', 2 union all
select 5 ,'bc', 2 union all
select 6 ,'b', 2 union all
select 7 ,'bc', 2
delete from Test_del
where name in (select name from Test_del group by name having COUNT(name) > 1)
and id not in (select MIN(id) from Test_del group by name having COUNT(name) >1)