从 MySQL 中具有多列的列表中获取最小值?
我们首先创建一个表 −
mysql> create table DemoTable756 ( Value1 int, Value2 int, Value3 int ); Query OK, 0 rows affected (0.62 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable756 values(10,20,14); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable756 values(20,34,17); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable756 values(200,134,789); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable756 values(139,98,99); Query OK, 1 row affected (0.17 sec)
使用 select 语句从表中显示所有记录 −
mysql> select *from DemoTable756;
这将产生以下输出 -
+--------+--------+--------+ | Value1 | Value2 | Value3 | +--------+--------+--------+ | 10 | 20 | 14 | | 20 | 34 | 17 | | 200 | 134 | 789 | | 139 | 98 | 99 | +--------+--------+--------+ 4 rows in set (0.00 sec)
以下是从具有多列的列表中获取最小值的查询 −
mysql> select least(Value1,Value2,Value3) from DemoTable756;
这将产生以下输出 -
+-----------------------------+ | least(Value1,Value2,Value3) | +-----------------------------+ | 10 | | 17 | | 134 | | 98 | +-----------------------------+ 4 rows in set (0.00 sec)
广告