主頁 > 知識庫 > sqlserver清除完全重復(fù)的數(shù)據(jù)只保留重復(fù)數(shù)據(jù)中的第一條

sqlserver清除完全重復(fù)的數(shù)據(jù)只保留重復(fù)數(shù)據(jù)中的第一條

熱門標(biāo)簽:服務(wù)外包 AI電銷 百度競價排名 網(wǎng)站排名優(yōu)化 鐵路電話系統(tǒng) 地方門戶網(wǎng)站 呼叫中心市場需求 Linux服務(wù)器
--創(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;
您可能感興趣的文章:
  • SQL Server數(shù)據(jù)庫刪除數(shù)據(jù)集中重復(fù)數(shù)據(jù)實例講解
  • Sql Server使用cursor處理重復(fù)數(shù)據(jù)過程詳解
  • SQL Server中刪除重復(fù)數(shù)據(jù)的幾個方法
  • sqlserver中重復(fù)數(shù)據(jù)值只取一條的sql語句
  • sqlserver合并DataTable并排除重復(fù)數(shù)據(jù)的通用方法分享
  • 教你幾種在SQLServer中刪除重復(fù)數(shù)據(jù)方法
  • MSSql簡單查詢出數(shù)據(jù)表中所有重復(fù)數(shù)據(jù)的方法

標(biāo)簽:黃山 衡水 蘭州 仙桃 湖南 銅川 崇左 湘潭

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《sqlserver清除完全重復(fù)的數(shù)據(jù)只保留重復(fù)數(shù)據(jù)中的第一條》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266