目前我有3个帐户使用相同的电子邮件地址,我想为按功能分组的同一个电子邮件地址提供哈希密钥。运行的sql语句是
UPDATE customers (
SELECT customer_id, email, email_hash FROM customers GROUP BY email) AS t1
SET email_hash='123' WHERE email='abc@abc.com'
当我运行此SQL查询时,我收到此错误。
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(select customer_id, email, email_hash, email_reg_status from customers group by' at line 1
如何使用group by函数为同一个电子邮件地址插入相同的哈希键?
答案 0 :(得分:1)
如果我理解你的正确性,你需要做的就是
update customers set email_hash='123' where email='abc@abc.com';
答案 1 :(得分:0)
由于email_id
对所有客户都相同;如果您在下面这样做,那么您的所有客户记录在email_hash
update customers set email_hash='123' where email='abc@abc.com';
我认为至少您的customer_id
字段是唯一的。在这种情况下,为什么不只是更新customer_id
,这是唯一的,如下所示
UPDATE customers SET email_hash='123' WHERE customer_id=<some_id_value>