是否可以在 MySQL 中执行 UPDATE 查询,仅在满足特定条件时才更新字段值?像这样的东西:
UPDATE test
SET
CASE
WHEN true
THEN field = 1
END
WHERE id = 123
换句话说:
UPDATE test
SET
something = 1, /*field that always gets updated*/
CASE
WHEN true
THEN field = 1 /*field that should only get updated when condition is met*/
END
WHERE id = 123
这样做的正确方法是什么?