sqlserver清除完全重復的數(shù)據(jù)只保留重復數(shù)據(jù)中的第一條
更新時間:2014年07月23日 16:43:41 投稿:whsnow
根據(jù)autoID刪除臨時表#tmp中的重復數(shù)據(jù),只保留每組重復數(shù)據(jù)中的第一條
--創(chuàng)建測試表 CREATE TABLE [dbo].[testtab]( [id] [nchar](10) NULL, [name] [nchar](10) NULL ) ; --向測試表插入測試數(shù)據(jù) insert into testtab values('1','1'); insert into testtab values('1','1'); insert into testtab values('2','2'); insert into testtab values('2','2'); insert into testtab values('3','3'); insert into testtab values('3','3'); --創(chuàng)建臨時表并向臨時表中插入測試表testtab中數(shù)據(jù)以及添加自增id:autoID select identity(int,1,1) as autoID, * into #Tmp from testtab --根據(jù)autoID刪除臨時表#tmp中的重復數(shù)據(jù),只保留每組重復數(shù)據(jù)中的第一條 delete #Tmp where autoID in(select max(autoID) from #Tmp group by id); --清除testtab表中的所有數(shù)據(jù) delete testtab; --向testtab表中插入#Tmp表中被處理過的數(shù)據(jù) insert into testtab select id,name from #Tmp; --刪除臨時表#Tmp drop table #Tmp;
相關文章
SQL Server附加數(shù)據(jù)庫報錯無法打開物理文件,操作系統(tǒng)錯誤5的圖文解決教程
sqlserver附加數(shù)據(jù)時,提示無法打開物理文件,操作系統(tǒng)錯誤5什么原因呢?今天小編給大家分享SQL Server附加數(shù)據(jù)庫報錯無法打開物理文件,操作系統(tǒng)錯誤5的圖文解決教程,一起看看吧2016-12-12詳解在SQLPlus中實現(xiàn)上下鍵翻查歷史命令的功能
這篇文章主要介紹了在SQLPlus中實現(xiàn)上下鍵翻查歷史命令的功能,這里介紹使用readline和rlwrap實現(xiàn)這個功能的方法,需要的朋友可以參考下2022-03-03SQL Server 2016里的sys.dm_exec_input_buffer的問題
這篇文章主要介紹了SQL Server 2016里的sys.dm_exec_input_buffer的相關資料,需要的朋友可以參考下2016-04-04將Reporting services的RDL文件拷貝到另外一臺機器時報Data at the root level i
在本機開發(fā)了一個Reporting后拷貝到服務器,然后在Sql Server Business Intelligence Development Studio中添加再打開后會報Data at the root level is invalid.錯誤2012-06-06