gpt4 book ai didi

mysql - 如何在 MySQL : if field value > 0 then minus one, 中执行此操作,否则就这样吧

转载 作者:可可西里 更新时间:2023-11-01 07:11:44 24 4
gpt4 key购买 nike

UPDATE tbl SET counts=counts-1 ...

最佳答案

如果 count 是您要更新的唯一列(或者,您没有在 where 子句中指定其他条件),那么您可以在 where 子句中执行此操作

UPDATE [Table] SET counts = counts - 1 WHERE counts > 0;

但是,如果您要更新同一查询中的其他列,这将不起作用。但是你有选择

UPDATE [Table] SET counts = MAX(counts - 1, 0);

UPDATE [Table] SET counts = CASE WHEN counts > 0 THEN counts - 1 ELSE 0 END;

关于mysql - 如何在 MySQL : if field value > 0 then minus one, 中执行此操作,否则就这样吧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2312126/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com