使用类似的与会者姓名和

时间:2017-10-26 14:56:04

标签: mysql sql

我有一个大型数据集,客户端导入了一个具有错误的与会者标识符且没有备份的事件,所以我的出生日期和性别是一致的,并且名称有点类似

table Attendees
---------------
id int(10) not null auto_increment,
AttendeeName varchar(255) not null,
Gender char(1) not null,
AttendeeID int(8) not null,
EventName varchar(255) not null

一个人可以参加很多活动

我可以使用正确和错误的ID和名称选择我需要更改的记录

作为一个例子,我有

John McKenna 90001232 Event1
John Mc Kenna   95131 Event2
John Doe            0 Event1
John Doe     90001122 Event2
Henry Hynes         0 Event1
Henry Hynes  90001211 Event2

我希望最终得到

John McKenna 90001232 Event1
John McKenna 90001232 Event2 etc

我尝试使用

select distinct(s.AttendeeName) AS CORRECTNAME
    , st.AttendeeName AS INCORRECTNAME
    , s.AttendeeID AS CORRECTID
    , st.AttendeeID AS INCORRECTID 
from #__Events s 
inner join #__Events st 
   on s.DateOfBirth = st.DateOfBirth 
  and soundex(s.AttendeeName) = soundex(st.AttendeeName) 
where s.Gender = st.Gender 
  and length(s.AttendeeID)= 8 
  and length(st.AttendeeID) < 8 
  and s.AttendeeName != st.AttendeeName 
order by s.AttendeeName;

问题是,我不知道如何构建更新语句任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

update x4tst_seed_times dest, (select distinct(s.SwimmerName) as INCORRECTNAME,st.SwimmerName as CORRECTNAME, s.SwimIrelandID as CORRECTID, st.SwimIrelandID AS INCORRECTID from x4tst_seed_times s inner join x4tst_seed_times st on s.DateOfBirth = st.DateOfBirth and soundex(s.SwimmerName) = soundex(st.SwimmerName) where length(s.SwimIrelandID)= 8 and length(st.SwimIrelandID) < 8 order by s.SwimmerName) src

设置dest.SwimIrelandID = src.CORRECTID,dest.SwimmerName = src.CORRECTNAME其中dest.DateOfBirth = src.DateOfBirth和dest.SwimmerName = src.CORRECTSWIMMERNAME和dest.SwimIrelandID = src.INCORRECTID;