delete a 
from 
    表 a 
where 
    exists(select 1 from 表 where col1=a.col1 and col2=a.col2 and sn<a.sn)

解决方案 »

  1.   

    delete 表 where sn not in(select min(sn) from 表 group by col1,col2)
      

  2.   

    select distinct col1,col2  into # from 表
    truncate table 表
    insert into 表 select * from #
    drop table #
      

  3.   

    可以換種思維呀﹐用  select DISTINCT * into newtable from  tb_name 把沒有重量的記錄放到另一個表中
      

  4.   

    select distinct * into #tmp from tb_name 
    drop table tb_name
    select * into tb_name from #tmp
    drop table #tmp 
      

  5.   

    DELETE L
     FROM tb_name L
         JOIN tb_name  R
    ON L.col1 = R.col1 AND L.col2 = R.col2 AND L.sn > R.sn
      

  6.   

    --建立测试环境
    declare @table1 table(sn  int,col1 int,col2 int)
    insert @table1 
    select 1,1,1 union
    select 2,1,1 union
    select 3,2,2 union
    select 4,2,2 union
    select 5,3,3 union
    select 6,3,3
    --执行
    delete from @table1  where sn in (select max(sn) from @table1 group by col1,col2 )
    --查看结果
    select * from @table1(所影响的行数为 6 行)
    (所影响的行数为 3 行)sn          col1        col2        
    ----------- ----------- ----------- 
    1           1           1
    3           2           2
    5           3           3(所影响的行数为 3 行)