我想仅在新字段较低时才更新字段的值。我尝试了这样的min,没有成功
UPDATE `editions` SET `editions`.`year` = MIN(`editions`.`year` , '2005') WHERE `editions`.`id` = 1;
我收到1064错误。如何在不先检索值的情况下更新值?
答案 0 :(得分:4)
UPDATE `editions`
SET `editions`.`year` =
LEAST(`editions`.`year` , '2005') WHERE `editions`.`id` = 1;
答案 1 :(得分:2)
您是否尝试过这样做:
update editions set year = 2005 where id = 1 and year > 2005;
(即将选择限制为您想要更新的行)