【发布时间】:2020-09-21 15:25:55
【问题描述】:
我正在尝试更新 mySQL 中的客户表,其中包含重复的电子邮件地址和唯一的 custom_ID。我想通过在 @ 符号前添加“+”和 customer_ID 来更改重复的电子邮件地址,但仅限于不唯一的电子邮件地址。
UPDATE clients SET email = REPLACE(email,'@', CONCAT('+',custom_ID,'@'))
INPUT
+-----------+-------------------------+
| custom_ID | email |
+-----------+-------------------------+
| 1001 | john.smith@live.com |
| 1002 | evyandy@email.net |
| 1007 | evyandy@email.net |
| 1012 | ann@live.com |
| 1020 | rick@yahoo.com |
| 1021 | ann@live.com |
| 1023 | evyandy@email.net |
| 1024 | emma@gmail.com |
+-----------+-------------------------+
OUTPUT
+-----------+----------------------------+
| custom_ID | email |
+-----------+----------------------------+
| 1001 | john.smith@live.com |
| 1002 | evyandy@email.net |
| 1007 | evyandy+1007@email.net |
| 1012 | ann@live.com |
| 1020 | rick@yahoo.com |
| 1021 | ann+1021@live.com |
| 1023 | evyandy+1023@email.net |
| 1024 | emma@gmail.com |
+-----------+----------------------------+
【问题讨论】:
-
您应该知道,并非所有电子邮件提供商都以相同的方式使用
+。不保证user+1@host.com和user+2@host.com会发送给同一个人。
标签: mysql sql email duplicates