我正在查询结果,我想将customer_id
复制到新表格字段old_customer_id
,customer_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 |
+-------------+-----------------+
答案 0 :(得分:0)
UPDATE YourTable
SET old_customer_id = customer_id, customer_id = 5
答案 1 :(得分:0)
您可以尝试两个单独的UPDATE
个查询。首先更新old_c_id
字段,然后更新c_id
。
类似的东西:
UPDATE customerTable
SET old_c_id = c_id;
然后,在另一个c_id
查询中设置UPDATE
。
不确定如果您在同一个查询中尝试过这两种情况会发生什么,可能有效:
UPDATE cTable
SET old_c_id = c_id, c_id = ??;
答案 2 :(得分:0)
UPDATE table_name SET old_customer_id = customer_id,customer_id = @your_new_customer_id;