如col1,col2重复记录较多. Select max(ID),col1,col2 into #temp
 from table1 as a
 group by col1,col2 truncate table table1 insert into table1
 select * from #temp drop table #temp

解决方案 »

  1.   

    选择时,以重复多的列 group by .
    再在主键上取大或取小都可以.
      

  2.   

    不是完全重复,例如:
    id      class     code    plant_money    fact_money    indate   
    1       0101       001      330.33        320.50        2002-01-02
    2       0101       001      330.33        320.50        2002-01-03
    3       0101       002      333.33        300.50        2003-01-01
    4       0102       001      22.2          21            2003-02-31
    5       0102       001      22.2          21            2003-02-31
    ………………
    要求其中class,code,plant_money,fact_money重复的只取一条记录,必须取到时间!
      

  3.   

    不是完全重复,例如:
    id      class     code    plant_money    fact_money    indate          ghs
    1       0101       001      330.33        320.50        2002-01-02     aaa
    2       0101       001      330.33        320.00        2002-01-03     bbb
    3       0101       001      330.33        320.00        2002-01-03     ddd
    4       0101       002      333.33        300.50        2003-01-01     ccc
    5       0102       001      22.2          21            2003-02-31     fff
    6       0102       001      22.2          21            2003-02-31     vvv
    ………………
    要求其中class,code,plant_money,fact_money重复的只取一条记录,如果class和code、plan_Money
    一样,则取fact_money最小的,必须取到时间和ghs!