Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 最小整数_Mysql_Int_Minimum - Fatal编程技术网

Mysql 最小整数

Mysql 最小整数,mysql,int,minimum,Mysql,Int,Minimum,我有这个疑问 UPDATE table SET this = this-20 WHERE this >= 0 我不希望此字段永远处于0以下。我是否可以向该查询中添加一些内容来确保这一点,而无需运行另一个查询 如果这是18,那么它将被设置为-2 (使用MYSQL)将条件更改为,其中(this-20)>=0。 并创建一个检查约束:ALTER TABLE[TABLE]添加约束thisgreeter大于零检查(this>=0)您可以使用最大的功能: UPDATE table SET this =

我有这个疑问

UPDATE table SET this = this-20 WHERE this >= 0
我不希望
字段永远处于0以下。我是否可以向该查询中添加一些内容来确保这一点,而无需运行另一个查询

如果这是18,那么它将被设置为-2


(使用MYSQL)

将条件更改为
,其中(this-20)>=0
。 并创建一个检查约束:
ALTER TABLE[TABLE]添加约束thisgreeter大于零检查(this>=0)

您可以使用最大的功能:

UPDATE table SET this = greatest(0,this-20) WHERE this >= 0
考虑到this-200,这基本上设置了该值的较大值