--創(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中的重復(fù)數(shù)據(jù),只保留每組重復(fù)數(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;
標(biāo)簽:湘潭 寧夏 預(yù)約服務(wù) 營口 周口 河源 欽州 鄂爾多斯
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《sqlserver清除完全重復(fù)的數(shù)據(jù)只保留重復(fù)數(shù)據(jù)中的第一條》,本文關(guān)鍵詞 sqlserver,清除,完全,重復(fù),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。