刪除重複資料

2021-05-27 04:42:45 字數 524 閱讀 2127

介紹兩種刪除重複行的方式

1.使用臨時表,分組找出重複部分的id進行刪除

刪除table:goods_info 中存在重複goods_id的記錄

select identity(int,1,1) as autoid,* into #temptable from goods_info

select min(autoid) as autoid into #temptable1 from #temptable group by goods_id --分組找出autoid

delete from #temptable where autoid in (select autoid from #temptable1)

2.使用分析函式刪除

with t as

(select  *, row_number() over (partition by ...  order by   ...) as rownum    from table_a

)delete from t   where rownum > 1;

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

mysql刪除重複資料

最近遇到刪除重複資料的問題,先分享一下解決辦法,如有不完善之處還望包涵!舉例如下 mysql select from table03 id name degree 1 fly 90 2 fly 90 3 fly 90 4 fly 80 5 wang 90 6 wang 90 7 wang 90 8 ...

刪除重複資料思路

1.在運算元據庫的時候往往會出現一條資料重複出現多次,而且沒有唯一標識的情況下該如何刪除重複資料呢?解決方案 先用distinct 查出所有不重複的資料,然後存入到乙個臨時表中,刪除現有表的所以資料,把臨時表資料匯入。select distinct into tmp from emp delete ...