将数字限制为最大值?
为此,您可以使用LEAST()
。以下是语法-
select least(yourColumnName,yourMaxValue) from yourTableName;
让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Number int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(50); mysql> insert into DemoTable values(40); mysql> insert into DemoTable values(30); mysql> insert into DemoTable values(201); mysql> insert into DemoTable values(60);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+--------+ | Number | +--------+ | 50 | | 40 | | 30 | | 201 | | 60 | +--------+ 5 rows in set (0.00 sec)
这是在MySQL中将数字限制为最大值的查询。我们将所有数字限制为最大值40-
mysql> select least(Number,40) from DemoTable;
输出结果
+------------------+ | least(Number,40) | +------------------+ | 40 | | 40 | | 30 | | 40 | | 40 | +------------------+ 5 rows in set (0.02 sec)