插入多行时,如何使用“ ON DUPLICATE KEY UPDATE”增加MySql中的字段?
对于一行:
INSERT INTO table (a, counter_elem) VALUES (1, 1) ON DUPLICATE KEY UPDATE counter_elem = counter_elem+1;
对于多行:
INSERT INTO table (a, counter_elem) VALUES (1, 1), (2, 1) ON DUPLICATE KEY UPDATE counter_elem = ?;
这不起作用:
counter_elem = VALUES(counter_elem)+1
完全一样!
INSERT INTO table (a, counter_elem) VALUES (1, 1), (2, 1) ON DUPLICATE KEY UPDATE counter_elem = counter_elem + 1;
那里没有问题!