2014-09-23 54 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