主页 > 知识库 > SQL Server数据库删除数据集中重复数据实例讲解

SQL Server数据库删除数据集中重复数据实例讲解

热门标签:如何在地图标注自己店铺 地图标注一个圆圈怎么用 广州人工电销机器人费用 怎样把地图标注导入公司地址 真人语音电销机器人 宁波人工外呼系统有效果吗 洛阳外呼系统平台 电销机器人被曝光 400外呼系统合法

SQL Server数据库操作中,有时对于表中的结果集,满足一定规则我们则认为是重复数据,而这些重复数据需要删除。如何删除呢?本文我们通过一个例子来加以说明。

例子如下:

如下只要companyName,invoiceNumber,customerNumber三者都相同,我们则认为是重复数据,下面的例子演示了如何删除。

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数据库删除数据集中重复数据的过程,希望本次的介绍能够对您有所收获!

您可能感兴趣的文章:
  • Sql Server使用cursor处理重复数据过程详解
  • sqlserver清除完全重复的数据只保留重复数据中的第一条
  • SQL Server中删除重复数据的几个方法
  • sqlserver中重复数据值只取一条的sql语句
  • sqlserver合并DataTable并排除重复数据的通用方法分享
  • 教你几种在SQLServer中删除重复数据方法
  • MSSql简单查询出数据表中所有重复数据的方法

标签:石家庄 烟台 晋中 北海 珠海 咸宁 南昌 东营

巨人网络通讯声明:本文标题《SQL Server数据库删除数据集中重复数据实例讲解》,本文关键词  SQL,Server,数据库,删除,数据,;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 下面列出与本文章《SQL Server数据库删除数据集中重复数据实例讲解》相关的同类信息!
  • 本页收集关于SQL Server数据库删除数据集中重复数据实例讲解的相关信息资讯供网民参考!
  • 推荐文章