我有一个包含三列和一堆行的表 table1
:
I have a table table1
with three columns and a bunch of rows:
[key_col|col_a|col_b]
我想用一组值更新 col_a(即保持 col_b
不变),如下所示:
I want to update col_a with a set of values (i.e. leaving col_b
unchanged), something like this:
INSERT INTO table1 AS t1 (key_col, col_a) VALUES ("k1", "foo"), ("k2", "bar");
但它不起作用,我该怎么做?
But it doesn't work, how do I do this?
你必须使用 UPDATE 而不是 INSERT:
You have to use UPDATE instead of INSERT:
例如:
UPDATE table1 SET col_a='k1', col_b='foo' WHERE key_col='1';
UPDATE table1 SET col_a='k2', col_b='bar' WHERE key_col='2';
这篇关于更新 MySQL 中的一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!