--删除重复的客户数据
update [dbo].[Customer] set Deleted=1, [Note]=ISNULL([Note],'')+'_id_'+CONVERT(nvarchar, Id )+'_clear_2020-12-10'
where Id in (
--查找重复的 a.PartnerId,a.SourceId 数据
select a.Id from [dbo].[Customer] a
left join (
--查找重复的 a.PartnerId,a.SourceId 数据
select a.PartnerId,a.SourceId from [dbo].[Customer] a
where a.Deleted=0
group by a.PartnerId,a.SourceId having count(a.Id)>1) table2
on a.PartnerId=table2.PartnerId and a.SourceId=table2.SourceId
where table2.PartnerId is not null)
and not exists (--这里换 not in 会慢
select 1 from (
select max(a.Id) as 'Id' from [dbo].[Customer] a
where a.Deleted=0
group by a.PartnerId,a.SourceId having count(a.Id)>1) c
where c.Id=[dbo].[Customer].Id
)