如何更新重复记录 [英] How to update duplicate records
本文介绍了如何更新重复记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
创建表#tempdata(sellerid int,custid varchar(50),sellerpmsid int,email varchar(100))
create table #tempdata(sellerid int,custid varchar(50),sellerpmsid int,email varchar(100))
推荐答案
你好,
你的意思是需要这个吗?
You mean to need this?
create table #tempdata(sellerid int,custid varchar(50),sellerpmsid int,email varchar(100))
insert into #tempdata values(31457,'SLND21353962',NULL,'aba@gmail.com')
go
insert into #tempdata values(31958,null,191,'aba@gmail.com')
go
insert into #tempdata values(30895,'ISL60259823',NULL,'adw@gmail.com')
go
insert into #tempdata values(31959,null,192,'adw@gmail.com')
--Query
;WITH CTE AS
(
select
sellerid,custid,sellerpmsid,email,
ROW_NUMBER() OVER (partition by email order by sellerid) as rn
from #tempdata
)
update T set sellerpmsid=T1.sellerpmsid
FROM CTE T
INNER JOIN CTE T1 ON T.email=T1.email AND T.rn+1=T1.rn
select * from #tempdata
最好的问候,
将
这篇关于如何更新重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文