表T1 字段 KIT INT,MMCU nvarchar(12),FRP decimal(29, 2),UPRC decimal(29, 4),CONV decimal(15, 7),TT nvarchar(1)
KIT         MMCU          FRP          UPRC        CONV      TT   
191714     B13100                      3.0000                 A
203239     B13100                      1.5000                 A
203239     B13100                      1.5000                 B 

209881     B13100        1.0000                               B        
210893     B13100        1.0000                               B 
....
....T1表是我整合所有數據之後得到的,因為要求是抓取沒有時間段內的資料,我用TT字段進行來表示變更前後的數據
現在表中會有如上紅色數據存在,因為UPRC所屬表中字段只有一個時間點,造成變更前和變更后都會抓到。想問下有什麽辦法在T1表中進行排除類似的重複數據,只保留一筆。

解决方案 »

  1.   

    ;with t as
    (
      select rn=row_number()over(partition by KIT,MMCU,FRP,UPRC,CONV,TT order by getdate()) 
      from t1
    )
    select * from t where rn=1  
      

  2.   


    select *
    from t1
    where not exists(
    select 1
    from t2
    where t1.kit=t2.kit and t1.tt>t2.tt
    )
      

  3.   

    ;with t as
    (
      select rn=row_number()over(partition by KIT,MMCU,FRP,UPRC,CONV order by getdate()) 
      from t1
    )
    select * from t where rn=1  去掉TT
      

  4.   

    TT字段還是要保留的,因為變更前後數據的區分就是TT。我是想將變更前後數據重複的排除掉,保留一筆。