SQL Server数据库删除数据集中重复数据实例讲解
SQL Server数据库操作中,有时对于表中的结果集,满足一定规则我们则认为是重复数据,而这些重复数据需要删除。如何删除呢?本文我们通过一个例子来加以说明。 例子如下: 如下只要companyName,invoiceNumber,customerNumber三者都相同,我们则认为是重复数据,下面的例子演示了如何删除。 insert @InvoiceListMasterselect N'华为',1001,100,200 union all select N'华为',300 union all select N'华为',301 union all select N'中兴',1002,200,1 union all select N'中兴',2 select * from @InvoiceListMaster DELETE A from ( select rown = ROW_NUMBER( )over( partition by companyname,invoicenumber,customerNumber order by companyname,customerNumber ),companyname,customerNumber from @InvoiceListMaster )a where exists ( select 1 from ( select rown = ROW_NUMBER( )over( partition by companyname,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 – 将pg_try_advisory_xact_lock()放在嵌套的子查询中?
- sql – 如何只保留一行表,删除重复的行?
- Transactional replication(事务复制)详解之如何跳过一个
- mssql 30万条数据 搜索文本字段的各种方式对比
- SQL Server 监控磁盘IO错误,msdb.dbo.suspect_pages
- SQL获取第一条记录的方法(sqlserver、oracle、mysql数据库)
- 必须会的SQL语句(八) 数据库的完整性约束
- 生成连续日期的sql临时表到左外连接到
- 不能执行查询,因为一些文件丢失或未注册 解决方法
- 谈谈sqlserver自定义函数与存储过程的区别