如何在不删除 MySql 中的整行的情况下用空白替换重复的列值?
How to replace duplicate column values with blank without deleting entire row in MySql?
我有一个mysql
tablecontacts
如下
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 |
我想在不影响 mobile
列的情况下将重复的电子邮件值(第一次出现除外)更新为 null
或空白。
解决方案应该类似于
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 |
有没有办法 IGNORE
复制电子邮件列值,但 mobile
值应该插入 table。
update contacts
set email = null
where id not in
(
select * from
(
select min(id)
from contacts
group by email
) tmp
)
我有一个mysql
tablecontacts
如下
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 |
我想在不影响 mobile
列的情况下将重复的电子邮件值(第一次出现除外)更新为 null
或空白。
解决方案应该类似于
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 |
有没有办法 IGNORE
复制电子邮件列值,但 mobile
值应该插入 table。
update contacts
set email = null
where id not in
(
select * from
(
select min(id)
from contacts
group by email
) tmp
)