位置:首頁 > 軟件操作教程 > 數(shù)據(jù)分析 > SQL > 問題詳情

SQL操作應(yīng)用——?jiǎng)h除重復(fù)記錄

提問人:ylm發(fā)布時(shí)間:2020-09-30评论0

刪除重復(fù)記錄
1),
delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)
2),select distinct * into temp from tablename
  delete from tablename
  insert into tablename select * from temp
評(píng)價(jià): 這種操作牽連大量的數(shù)據(jù)的移動(dòng),這種做法不適合大容量但數(shù)據(jù)操作
3),例如:在一個(gè)外部表中導(dǎo)入數(shù)據(jù),由于某些原因第一次只導(dǎo)入了一部分,但很難判斷具體位置,這樣只有在下一次全部導(dǎo)入,這樣也就產(chǎn)生好多重復(fù)的字段,怎樣刪除重復(fù)字段

alter table tablename
--添加一個(gè)自增列
add  column_b int identity(1,1)
 delete from tablename where column_b not in(
select max(column_b)  from tablename group by column1,column2,...)
alter table tablename drop column column_b

繼續(xù)查找其他問題的答案?

相關(guān)視頻回答
回復(fù)(0)
X
返回頂部
付费复制

付费获取七天复制权限

限时特价:2.88元/篇原价:10元
联系客服

扫码关注公众号,发送私信联系客服.

微信扫码关注,联系客服

联系客服QQ:2845411722

恭喜您,操作成功,可以复制了

3秒后关闭
X