是可以這樣做的
select
replace('[email protected]',
substring_index(substring_index('[email protected]','@',-1),'.',1),
concat(substring_index(substring_index('[email protected]','@',-1),'.',1),'1')
)
這裏有幾個測試
mysql> select
-> replace('[email protected]',
-> substring_index(substring_index('[email protected]','@',-1),'.',1),
-> concat(substring_index(substring_index('[email protected]','@',-1),'.',1),'1')
->) as result ;
+---------------------------------+
| result |
+---------------------------------+
| [email protected] |
+---------------------------------+
1 row in set (0.00 sec)
mysql> select
-> replace('[email protected]',
-> substring_index(substring_index('[email protected]','@',-1),'.',1),
-> concat(substring_index(substring_index('[email protected]','@',-1),'.',1),'1')
->
->) as result ;
+------------------------------+
| result |
+------------------------------+
| [email protected] |
+------------------------------+
mysql> select
-> replace('[email protected]',
-> substring_index(substring_index('[email protected]','@',-1),'.',1),
-> concat(substring_index(substring_index('[email protected]','@',-1),'.',1),'1')
->
->) as result ;
+----------------------------------+
| result |
+----------------------------------+
| [email protected] |
+----------------------------------+
1 row in set (0.00 sec)
因此,這裏是更新命令
update your_table set email =
replace(
email,
substring_index(substring_index(email,'@',-1),'.',1),
concat(substring_index(substring_index(email,'@',-1),'.',1),'1')
) ;
我不認爲這可以通過查詢來完成獨自一人。您可能需要使用PHP將'1'放在正確的位置 – asprin
可以通過替換上次出現的「。」來完成。 – Manwal
@Manwal不可能。如果這個ID是[email protected] – paradox