mysql中的递减值但不是负数 [英] Decrement value in mysql but not negative
本文介绍了mysql中的递减值但不是负数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户在php和mysql中删除它时,我想减小一个值.我要检查是否小于0.如果值为0,则不要减量.
I want to decrement a value when user delete it in php and mysql. I want to check not to go below than 0. If value is 0 then do not decrement.
mysql_query("UPDATE table SET field = field - 1 WHERE id = $number");
如果字段为 0 ,则不执行任何操作
If field is 0 then do not do anything
推荐答案
添加另一个条件,仅在field
大于0
Add another condition to update only if the field
is greater 0
UPDATE table
SET field = field - 1
WHERE id = $number
and field > 0
这篇关于mysql中的递减值但不是负数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文