首页 文章资讯内容详情

从MySQL表格的整个四列中找到最低分

2026-06-05 1 花语

要从全部四列中找到最低分,请使用MySQLLEAST()函数。让我们首先创建一个表-

create table DemoTable( Score1 int, Score2 int, Score3 int, Score4 int );

使用插入命令在表中插入一些记录-

insert into DemoTable values(88,76,45,56); insert into DemoTable values(99,78,87,34); insert into DemoTable values(34,32,56,98);

使用select语句&minsu;显示表中的所有记录。

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)

以下是从数据库的四列中查找最低分数的查询-

select least(Score1,Score2,Score3,Score4) AS MinimumScore from DemoTable;

这将产生以下输出-

+--------------+ | MinimumScore | +--------------+ | 45 | | 34 | | 32 | +--------------+ 3 rows in set (0.00 sec)