SQL中刪除重複的行 重複資料 ,只保留一行

2021-06-12 23:17:14 字數 459 閱讀 6231

sql中刪除重複的行(重複資料),只保留一行

方法一:使用在t-sql的程式設計中

分配乙個列號碼,以col1,col2組合來分割槽排序,刪除database重複的行(重複資料),只保留一行

// col1,col2是資料庫database的字段

delete a from (select col1,col2,row_number() over (partition by col1,col2 order by col1) as rn from database) a where a.rn>1

方法二:使用在etl中

select distant into,這種方法借助乙個新的table,把不重複的結果集轉移到新table中

select distinct col1, col2 into nodups

from dup1;

select * from nodups

sql刪除重複資料

1 建立表 create table dbo test id numeric 18,0 identity 1,1 not null primary key,name varchar 200 collate chinese prc ci as null remark varchar 1024 coll...

sql刪除重複資料

sql刪除重複資料 如果該錶需要刪除重複的記錄 重覆記錄保留1條 可以按以下方法刪除 select distinct into tmp from tablename drop table tablename select into tablename from tmp drop table tmp ...

SQL刪除重複資料

這個應用場景也不多說了 with c as select orderid,row number over partition by orderid order by select null as nfrom sales.myorders delete from c where n 1 利用row n...