是否有可能在 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
做这件事的正确方法是什么?