0

假设我有一个包含两列的简单表格,userid并且email.

如何更改值存在于多行email中的所有值?email

例如,假设该emailblah@blah.com存在于 4 行中。我不想删除这 4 行,我只想将email所有 4 行的列设置为''.

什么查询会在 MySQL 中做到这一点?

4

2 回答 2

0

此请求获取存在于 1 行以上的电子邮件:

SELECT email, COUNT(email) AS c
FROM table 
GROUP BY email
HAVING c > 1

因此,您只需在更新查询中使用它:

UPDATE table SET email = ''
WHERE email IN (
     SELECT email, COUNT(email) AS c
     FROM table 
     GROUP BY email
     HAVING c > 1
)
于 2012-05-16T16:43:35.767 回答
0
Update t
Set t.Email = ''
Where t.Email in (Select email from YourTable group by email having count(*)>1)
于 2012-05-16T16:44:11.180 回答