从 MySQL 的四列中找到最小分数
要从四列中找到最小分数,请使用 MySQL LEAST() 函数。让我们首先创建一个表 -
mysql> create table DemoTable( Score1 int, Score2 int, Score3 int, Score4 int ); Query OK, 0 rows affected (0.50 sec)
使用 insert 命令向表中插入一些记录 -
mysql> insert into DemoTable values(88,76,45,56); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(99,78,87,34); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(34,32,56,98); Query OK, 1 row affected (0.44 sec)
使用 select 语句 &minsu;显示表中的所有记录
mysql> select *from DemoTable;
这将产生以下输出 -
+--------+--------+--------+--------+ | Score1 | Score2 | Score3 | Score4 | +--------+--------+--------+--------+ | 88 | 76 | 45 | 56 | | 99 | 78 | 87 | 34 | | 34 | 32 | 56 | 98 | +--------+--------+--------+--------+ 3 rows in set (0.00 sec)
以下是查找数据库四列中的最小分数的查询 -
mysql> select least(Score1,Score2,Score3,Score4) AS MinimumScore from DemoTable;
这将产生以下输出 -
+--------------+ | MinimumScore | +--------------+ | 45 | | 34 | | 32 | +--------------+ 3 rows in set (0.00 sec)
广告