SQL Server數(shù)據(jù)庫(kù)刪除數(shù)據(jù)集中重復(fù)數(shù)據(jù)實(shí)例講解
SQL Server數(shù)據(jù)庫(kù)操作中,有時(shí)對(duì)于表中的結(jié)果集,滿(mǎn)足一定規(guī)則我們則認(rèn)為是重復(fù)數(shù)據(jù),而這些重復(fù)數(shù)據(jù)需要?jiǎng)h除。如何刪除呢?本文我們通過(guò)一個(gè)例子來(lái)加以說(shuō)明。
例子如下:
如下只要companyName,invoiceNumber,customerNumber三者都相同,我們則認(rèn)為是重復(fù)數(shù)據(jù),下面的例子演示了如何刪除。
declare @InvoiceListMaster table ( ID int identity primary key , companyName Nchar(20), invoiceNumber int, CustomerNumber int, rmaNumber int ) insert @InvoiceListMaster select N'華為', 1001,100,200 union all select N'華為', 1001,100,300 union all select N'華為', 1001,100,301 union all select N'中興', 1002, 200,1 union all select N'中興', 1002, 200,2 select * from @InvoiceListMaster DELETE A from ( select rown = ROW_NUMBER( )over( partition by companyname, invoicenumber, customerNumber order by companyname, invoicenumber, customerNumber ), companyname, invoicenumber, customerNumber from @InvoiceListMaster )a where exists ( select 1 from ( select rown = ROW_NUMBER( )over( partition by companyname, invoicenumber, customerNumber order by companyname, invoicenumber, customerNumber ), companyname, invoicenumber, customerNumber from @InvoiceListMaster ) b where b.companyName = a.companyName and b.invoiceNumber = a.invoiceNumber and b.CustomerNumber = a.CustomerNumber and a.rown > b.rown ) select * from @InvoiceListMaster
以上的例子就演示了SQL Server數(shù)據(jù)庫(kù)刪除數(shù)據(jù)集中重復(fù)數(shù)據(jù)的過(guò)程,希望本次的介紹能夠?qū)δ兴斋@!
相關(guān)文章
SQL update 多表關(guān)聯(lián)更新的實(shí)現(xiàn)代碼
這篇文章主要介紹了SQL update 多表關(guān)聯(lián)更新的實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-09-09
sql not in 與not exists使用中的細(xì)微差別
用的時(shí)候我們只注重查詢(xún)的效率,但卻往往會(huì)忽略一下比較細(xì)小的區(qū)別2013-02-02
眾所周知,在M$sql中有個(gè)絕對(duì)是網(wǎng)絡(luò)安全中的隱患的帳號(hào)sa,系統(tǒng)管理員 (sa),默認(rèn)情況下,它指派給固定服務(wù)器角色 sysadmin,并不能進(jìn)行更改。這個(gè)sa一般情況下是既不可以更改名稱(chēng),也不可以刪除,呵呵,有點(diǎn)雞肋的味道,棄置可惜,食之無(wú)味。裝上sql2000之后,感覺(jué)怪怪的,放著這個(gè)后門(mén)在,始終都不放心,擔(dān)心有一天被人破出密碼,那偶的電腦不就完拉??赡苣慊卣f(shuō)設(shè)個(gè)強(qiáng)壯點(diǎn)的密碼,這個(gè)辦法是可行,可不是長(zhǎng)久之記,所謂斬草要除根,要是把sa給刪拉就不用擔(dān)心那些"黑客"暴力破解拉。2008-04-04
SQL Server復(fù)制功能要避開(kāi)缺陷的干擾小結(jié)
SQL Server具有強(qiáng)大的復(fù)制功能,除了將數(shù)據(jù)和數(shù)據(jù)庫(kù)對(duì)象從一個(gè)數(shù)據(jù)庫(kù)復(fù)制并準(zhǔn)確分發(fā)的另一個(gè)數(shù)據(jù)庫(kù)中,還要實(shí)行數(shù)據(jù)庫(kù)之間的同步。2011-03-03
沒(méi)有SQL Server數(shù)據(jù)庫(kù)時(shí)如何打開(kāi).MDF文件
本文主要介紹了在安裝有Visual Studio 2005或以上的版本的前提下,沒(méi)有安裝SQL Server數(shù)據(jù)庫(kù)也可以打開(kāi).MDF數(shù)據(jù)庫(kù)文件的方法,需要的朋友可以參考下2015-08-08
SQL Server誤區(qū)30日談 第6天 有關(guān)NULL位圖的三個(gè)誤區(qū)
NULL位圖是為了確定行中的哪一列是NULL值,哪一列不是。這樣做的目的是當(dāng)Select語(yǔ)句后包含存在NULL值的列時(shí),避免了存儲(chǔ)引擎去讀所有的行來(lái)查看是否是NULL,從而提升了性能2013-01-01
sqlserver 多表查詢(xún)不同數(shù)據(jù)庫(kù)服務(wù)器上的表
sqlserver中多表查詢(xún)不同數(shù)據(jù)庫(kù)服務(wù)器上的表的實(shí)現(xiàn)方法,需要的朋友可以參考下2012-04-04
SQL Server 2012 安裝與啟動(dòng)圖文教程
本文通過(guò)圖文并茂的形式給大家介紹了sqlserver2012的安裝步驟,本文分步驟給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧2016-11-11

