如何在单个查询中批量或批量更新mysql

时间:2016-05-09 20:58:10

标签: mysql

我已经尝试了这两种方法,我的表永远不会更新。它保持不变。我做错了什么?

UPDATE localhost_campaigns.list_name_counter SET counter = (CASE purl WHEN 'dingo' THEN '1' WHEN 'koala' THEN '0' END) WHERE purl IN (dingo, koala);

UPDATE localhost_campaigns.list_name_counter SET counter = CASE WHEN purl = 'dingo' THEN '1' WHEN purl = 'koala' THEN '0' END WHERE purl IN (dingo, koala);

1 个答案:

答案 0 :(得分:1)

作为一个真正的解决方案;

为字符串使用引号。

UPDATE localhost_campaigns.list_name_counter 
SET counter = (CASE purl WHEN 'dingo' THEN '1' WHEN 'koala' THEN '0' END) 
WHERE purl IN ("dingo", "koala");