sql 刪除重複資料語句

2021-06-08 10:17:02 字數 534 閱讀 1740

現在有表資料如下圖1

需要刪除表中除id外重複的資料,實現如下圖所示效果圖2

篩選根據name,value分組後id最大的非重複資料:select max(id) from deleterepeat group by (name+value);

下面是實現效果圖2 的語句

delete from deleterepeat where id not in(select max(id) from deleterepeat group by (name+value))

實現效果等於下邊語句

select * from deleterepeat where id  in(select max(id) from deleterepeat group by (name+value));

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...