sqlserver清除完全重復(fù)的數(shù)據(jù)只保留重復(fù)數(shù)據(jù)中的第一條
--創(chuàng)建測(cè)試表
CREATE TABLE [dbo].[testtab](
[id] [nchar](10) NULL,
[name] [nchar](10) NULL
) ;
--向測(cè)試表插入測(cè)試數(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)建臨時(shí)表并向臨時(shí)表中插入測(cè)試表testtab中數(shù)據(jù)以及添加自增id:autoID
select identity(int,1,1) as autoID, * into #Tmp from testtab
--根據(jù)autoID刪除臨時(shí)表#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;
--刪除臨時(shí)表#Tmp
drop table #Tmp;
相關(guān)文章
關(guān)于數(shù)據(jù)庫優(yōu)化問題收集匯總
筆者在工作實(shí)踐中發(fā)現(xiàn),不良的SQL往往來自于不恰當(dāng)?shù)乃饕O(shè)計(jì)、不充份的連接條件和不可優(yōu)化的where子句。以下就對(duì)數(shù)據(jù)庫優(yōu)化問題進(jìn)行了介紹,需要的朋友可以參考下2013-07-07
SQL Server附加數(shù)據(jù)庫報(bào)錯(cuò)無法打開物理文件,操作系統(tǒng)錯(cuò)誤5的圖文解決教程
sqlserver附加數(shù)據(jù)時(shí),提示無法打開物理文件,操作系統(tǒng)錯(cuò)誤5什么原因呢?今天小編給大家分享SQL Server附加數(shù)據(jù)庫報(bào)錯(cuò)無法打開物理文件,操作系統(tǒng)錯(cuò)誤5的圖文解決教程,一起看看吧2016-12-12
Sql Server數(shù)據(jù)庫各版本功能對(duì)比
這篇文章主要介紹了Sql Server數(shù)據(jù)庫各版本功能對(duì)比的相關(guān)資料,包括各個(gè)版本新增的功能介紹,需要的朋友可以參考下2017-05-05
詳解在SQLPlus中實(shí)現(xiàn)上下鍵翻查歷史命令的功能
這篇文章主要介紹了在SQLPlus中實(shí)現(xiàn)上下鍵翻查歷史命令的功能,這里介紹使用readline和rlwrap實(shí)現(xiàn)這個(gè)功能的方法,需要的朋友可以參考下2022-03-03
SQL Server 2016里的sys.dm_exec_input_buffer的問題
這篇文章主要介紹了SQL Server 2016里的sys.dm_exec_input_buffer的相關(guān)資料,需要的朋友可以參考下2016-04-04
將Reporting services的RDL文件拷貝到另外一臺(tái)機(jī)器時(shí)報(bào)Data at the root level i
在本機(jī)開發(fā)了一個(gè)Reporting后拷貝到服務(wù)器,然后在Sql Server Business Intelligence Development Studio中添加再打開后會(huì)報(bào)Data at the root level is invalid.錯(cuò)誤2012-06-06
SQL處理多級(jí)分類,查詢結(jié)果呈樹形結(jié)構(gòu)
對(duì)于多級(jí)分類常規(guī)的處理方法,很多程序員可能是用程序先讀取一級(jí)分類記錄,然后通過一級(jí)分類循環(huán)讀取下面的子分類2012-08-08

