Sql server 刪除重覆記錄的SQL語句

2022-05-06 01:03:09 字數 1025 閱讀 1313

在專案開發過程中有個模組日清表頁面資料重複,當時那個頁面的資料是查詢n多個表,晚上跑的定時任務執行昨天的sql語句,為了方便修改用的儲存跑的。

資料重複了,在測試伺服器上沒有類似的情況發生。

並且不能刪除掉資料。

緊急情況下,先將源頭查詢查詢資料過濾掉,將原有表結構複製乙份修改成copy表,然後將歷史資料根據時間段一點一點查詢出來,然後將兩個檔名稱調換。

可是重複資料如何刪除呢:

select

*from

today_order t

inner

join

(

select

tt.platform_number,tt.payment_bh,

max (tt.id) as

id

from

today_order tt

group

bytt.platform_number,tt.payment_bh

) a

on t.platform_number = a.platform_number and t.payment_bh=

a.payment_bh

and t.id <> a.id

delete

tfrom

today_order t

inner

join

(

select

tt.platform_number,tt.payment_bh,

max (tt.id) as

id

from

today_order tt

group

bytt.platform_number,tt.payment_bh

) a

on t.platform_number = a.platform_number and t.payment_bh=

a.payment_bh

and t.id <> a.id

SQL Server刪除重覆記錄?

sql server中有重複的資料,所有的字段都一樣,需要刪除重複的,僅保留一條,怎麼辦?假設你的表名為table1,其中有一列column1資料型別為int,它們的值都是1 注意,其他不重複的行此列不能是1,否則必須增加條件直到根據條件返回的行只包含你要刪除的行 declare count int...

刪除重覆記錄

我們經常在資料庫中有重複的記錄這時候我們希望刪除那些重複的記錄 你不要告訴我你是一條條手動刪除的哈 select distinct into newtable form 程式設計客棧nbsp tablename drop table tabwww.cppcns.comlename select in...

SQL查詢重覆記錄,刪除重覆記錄

1 查詢表中多餘的重覆記錄,重覆記錄是根據單個字段 docid 來判斷 select from tablename where docid in select docid from tablename group by docid h ing count docid 1 例二 select from...