Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何将一列的值复制到同一行中的另一列中?_Mysql_Sql - Fatal编程技术网

Mysql 如何将一列的值复制到同一行中的另一列中?

Mysql 如何将一列的值复制到同一行中的另一列中?,mysql,sql,Mysql,Sql,这是我的示例表: +-----+----------+------+ | id | current | max | +-----+----------+------+ | 1 | 20 | 100 | | 2 | 50 | 50 | +-----+----------+------+ 我需要一个查询,将行的current列的值设置为其max列,但我找不到复制它的方法。这是我当前的查询: UPDATE `table` SET `current` = ?

这是我的示例表:

+-----+----------+------+
| id  | current  | max  |
+-----+----------+------+
| 1   | 20       | 100  |
| 2   | 50       | 50   |
+-----+----------+------+
我需要一个查询,将行的
current
列的值设置为其
max
列,但我找不到复制它的方法。这是我当前的查询:

UPDATE `table` SET `current` = ??? WHERE `id` = 1

如果要使用该列的值100,我将用什么替换

只需使用列名将其设置为该列的值:

UPDATE `table` SET `current` = `max` WHERE `id` = 1

只需使用列名将其设置为该列值:

UPDATE `table` SET `current` = `max` WHERE `id` = 1

要使用
max
列中的值更新列
current
,仅更新行id1,请使用此脚本

UPDATE table 
SET    current = max
WHERE  id = 1;
要使用表中所有行的
max
列中的值更新列
current
,请删除
WHERE
条件

UPDATE table 
SET    current = max;

要使用
max
列中的值更新列
current
,仅更新行id1,请使用此脚本

UPDATE table 
SET    current = max
WHERE  id = 1;
要使用表中所有行的
max
列中的值更新列
current
,请删除
WHERE
条件

UPDATE table 
SET    current = max;