gpt4 book ai didi

MySQL将查询记录复制到新表字段并更新当前记录

转载 作者:行者123 更新时间:2023-11-30 00:36:09 26 4
gpt4 key购买 nike

我正在查询结果,我想将customer_id复制到新表字段old_customer_idcustomer_id将替换最新记录.

+-------------+-----------------+
| customer_id | old_customer_id |
|-------------+-----------------+
| 5 | |
| 3 | |
| 1 | |
+-------------+-----------------+

在我的查询得到如上结果后,我想将 customer_id 复制到 old_customer_id ,它会

+-------------+-----------------+
| customer_id | old_customer_id |
|-------------+-----------------+
| 5 | 5 |
| 5 | 3 |
| 5 | 1 |
+-------------+-----------------+

最佳答案

UPDATE YourTable
SET old_customer_id = customer_id, customer_id = 5

DEMO

关于MySQL将查询记录复制到新表字段并更新当前记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22161925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com