SQL Server數(shù)據(jù)庫(kù)刪除數(shù)據(jù)集中重復(fù)數(shù)據(jù)實(shí)例講解
SQL Server數(shù)據(jù)庫(kù)操作中,有時(shí)對(duì)于表中的結(jié)果集,滿足一定規(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 Server自動(dòng)生成日期加數(shù)字的序列號(hào)
需要生成下面的序列號(hào),前半部分是yyyymmdd格式的年月日時(shí)間數(shù)字,后半部分則是每天都從1順序增長(zhǎng)的數(shù)字,位數(shù)要固定,中間不足的補(bǔ)0。2009-08-08SQL Server數(shù)據(jù)庫(kù)重命名、數(shù)據(jù)導(dǎo)出的方法說(shuō)明
這篇文章主要介紹了SQL Server數(shù)據(jù)庫(kù)重命名、數(shù)據(jù)導(dǎo)出、更改數(shù)據(jù)庫(kù)所有者的方法說(shuō)明,大家參考使用吧2013-11-11詳解SqlServer數(shù)據(jù)庫(kù)中Substring函數(shù)的用法
substring操作的字符串,開(kāi)始截取的位置,返回的字符個(gè)數(shù),本文通過(guò)簡(jiǎn)單實(shí)例給大家介紹了SqlServer數(shù)據(jù)庫(kù)中Substring函數(shù)的用法,感興趣的朋友一起看看吧2018-04-04SQL?Server快速?gòu)氐仔遁d實(shí)例方法分享
最近在安裝了SQL Server后,當(dāng)由于某些原因我們需要卸載它時(shí),我們應(yīng)該怎么操作呢?這篇文章主要給大家介紹了關(guān)于SQL?Server快速?gòu)氐仔遁d的相關(guān)資料,需要的朋友可以參考下2023-10-10獲取MSSQL 表結(jié)構(gòu)中字段的備注、主鍵等信息的sql
本文為大家詳細(xì)介紹下如何獲取MSSQL 表結(jié)構(gòu)中字段的備注、主鍵等信息,感興趣的朋友可以參考下2013-09-09Sql Server Management Studio連接Mysql的實(shí)現(xiàn)步驟
本文主要介紹了Sql Server Management Studio連接Mysql的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04修復(fù)斷電等損壞的SQL 數(shù)據(jù)庫(kù)
修復(fù)斷電等損壞的SQL 數(shù)據(jù)庫(kù),不論因?yàn)槟姆N原因,大家都可以測(cè)試下,試試。2009-08-08