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ū)δ兴斋@!
標(biāo)簽:石家莊 煙臺(tái) 晉中 北海 珠海 咸寧 南昌 東營(yíng)
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《SQL Server數(shù)據(jù)庫(kù)刪除數(shù)據(jù)集中重復(fù)數(shù)據(jù)實(shí)例講解》,本文關(guān)鍵詞 SQL,Server,數(shù)據(jù)庫(kù),刪除,數(shù)據(jù),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。