alter table 表 add  newfield int identity(1,1)delete 表
where newfield not in(
 select min(newfield) from 表 group by user_id,date,sl
 )alter table 表 drop column newfield

解决方案 »

  1.   

    select * into #temp from 表 group by user_id,date,sl 
    truncate table 表
    insert 表 select * from #temp
    drop table #temp
      

  2.   

    select distinct * into newtable from yourtable
    drop table yourtable
    exec sp_rename newtable,yourtable
    请问一下大力:我用以上方法与用你的第一种方法在性能上有什么缺点?
      

  3.   

    哦,呵呵
    我是说
    : pengdali(大力) ( ) 信誉:376 alter table 表 add  newfield int identity(1,1)delete 表
    where newfield not in(
     select min(newfield) from 表 group by user_id,date,sl
     )alter table 表 drop column newfield
    方法很好
      

  4.   

    alter table 表 add  newfield int identity(1,1)DELETE L
        FROM taable L
             JOIN table R
                           ON L.user_id " = R.user_id  
     AND L.newfield  > R.newfield alter table 表 drop column newfield
      

  5.   

    打错了 改一下alter table 表 add  newfield int identity(1,1)DELETE L
        FROM taable L
             JOIN table R
                           ON L.user_id  = R.user_id  
     AND L.newfield  > R.newfield alter table 表 drop column newfield
      

  6.   

    觉得distinct到临时表效率好写
      

  7.   

    我也喜欢用大力的第一种方法。sql最好都加上字增字段列。这是我个人意见
      

  8.   

    to pengdali(大力) 兄:
      你的做法会把所有重复的行删掉。
      
      但是如果表中有不重复的行和有重复的行?
      这时应该怎么办?
      
      
      

  9.   

    yoki(小马哥) 的做法会丢失一些约束