2014-09-23 51 views
1

我有几个Gmail邮箱地址,我的表的MySQL从电子邮件中删除点地址

[email protected] 
[email protected] 
[email protected] 
[email protected] 

我需要更换地址的Gmail包含符号“” 获得:

[email protected] 
[email protected] 
[email protected] 
[email protected] 

我的查询不起作用

UPDATE voters set email 
replace(substring(email, 1, LOCATE('@', email) -1), '.', '') 
WHERE email REGEXP '@googlemail.com|@gmail.com' 

请大家帮忙,THX!

回答

1

@之前你提取子和更换点,但你的@后正在不添加回子你在这之后:

UPDATE voters 
SET email = CONCAT(replace(substring(email, 1, LOCATE('@', email) -1), '.', ''), 
        SUBSTRING(email, LOCATE('@', email))) 
WHERE email REGEXP '@googlemail.com|@gmail.com' 

DEMO

0

您可以使用使用如下面的查询类似的东西substring_index & substring

UPDATE table1 
SET email = CONCAT (
     replace(substring_index(email, '@', 1), '.', '') 
     ,substring(email, instr(email, '@')) 
     ) 
WHERE substring_index(email, '@', -1) IN (
     'googlemail.com' 
     ,'gmail.com' 
     ); 

SQLFiddle