表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表中進行排除類似的重複數據,只保留一筆。
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表中進行排除類似的重複數據,只保留一筆。
(
select rn=row_number()over(partition by KIT,MMCU,FRP,UPRC,CONV,TT order by getdate())
from t1
)
select * from t where rn=1
select *
from t1
where not exists(
select 1
from t2
where t1.kit=t2.kit and t1.tt>t2.tt
)
(
select rn=row_number()over(partition by KIT,MMCU,FRP,UPRC,CONV order by getdate())
from t1
)
select * from t where rn=1 去掉TT