SQL Server數(shù)據(jù)庫刪除數(shù)據(jù)集中重復(fù)數(shù)據(jù)實例講解
SQL Server數(shù)據(jù)庫操作中,有時對于表中的結(jié)果集,滿足一定規(guī)則我們則認(rèn)為是重復(fù)數(shù)據(jù),而這些重復(fù)數(shù)據(jù)需要刪除。如何刪除呢?本文我們通過一個例子來加以說明。
例子如下:
如下只要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ù)庫刪除數(shù)據(jù)集中重復(fù)數(shù)據(jù)的過程,希望本次的介紹能夠?qū)δ兴斋@!
相關(guān)文章
SQL Server數(shù)據(jù)庫重命名、數(shù)據(jù)導(dǎo)出的方法說明
這篇文章主要介紹了SQL Server數(shù)據(jù)庫重命名、數(shù)據(jù)導(dǎo)出、更改數(shù)據(jù)庫所有者的方法說明,大家參考使用吧2013-11-11詳解SqlServer數(shù)據(jù)庫中Substring函數(shù)的用法
substring操作的字符串,開始截取的位置,返回的字符個數(shù),本文通過簡單實例給大家介紹了SqlServer數(shù)據(jù)庫中Substring函數(shù)的用法,感興趣的朋友一起看看吧2018-04-04獲取MSSQL 表結(jié)構(gòu)中字段的備注、主鍵等信息的sql
本文為大家詳細介紹下如何獲取MSSQL 表結(jié)構(gòu)中字段的備注、主鍵等信息,感興趣的朋友可以參考下2013-09-09Sql Server Management Studio連接Mysql的實現(xiàn)步驟
本文主要介紹了Sql Server Management Studio連接Mysql的實現(xiàn)步驟,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04