如果Field2不重复: delete a from 表 a where exists(select 1 from 表 where Field1=a.Field1 and Field2<a.Field2) 否则: select identity(int,1,1) as id,* into #t from 表truncate table 表insert into 表 select Field1,Field2 from #T a where not exists(select 1 from #T where Field1=a.Field1 and id<a.id) drop table #T
insert into # select distinct * from t insert into t select * from # drop table 3
delete a from 表 a where exists(select 1 from 表 where Field1=a.Field1 and Field2<a.Field2) 否则:
select identity(int,1,1) as id,* into #t from 表truncate table 表insert into 表
select Field1,Field2 from #T a
where not exists(select 1 from #T where Field1=a.Field1 and id<a.id) drop table #T
insert into t select * from #
drop table 3
2.2个字段完全相等算重复数据还是只要Field1重复就算重复数据?
如果是2的后者保留那条记录?
where field1 in (select field1 from 表
group by field1
having count(1)>1)