我有一个mysql
表contacts
如下
id | email | mobile |
1 | abc123@xyz.com | 9800000023 |
2 | abc123@xyz.com | 9800000021 |
3 | pqr111@xyz.com | 9800000034 |
4 | pqr123@xyz.com | 9900000033 |
5 | abc111@xyz.com | 9804400000 |
6 | pqr111@xyz.com | 9800500000 |
7 | abc111@xyz.com | 8600000000 |
我想要将重复的电子邮件值(第一次出现除外)更新为 null
或空白,而不影响 mobile
列。
解决方案应该如下所示
id | email | mobile |
1 | abc123@xyz.com | 9800000023 |
2 | <null> | 9800000021 |
3 | pqr111@xyz.com | 9800000034 |
4 | pqr123@xyz.com | 9900000033 |
5 | abc111@xyz.com | 9804400000 |
6 | <null> | 9800500000 |
7 | <null> | 8600000000 |
有没有办法忽略
重复的电子邮件列值,但应将移动
值插入表中。
最佳答案
update contacts
set email = null
where id not in
(
select * from
(
select min(id)
from contacts
group by email
) tmp
)
关于mysql - 如何用空白替换重复的列值而不删除 MySql 中的整行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38732320/