從 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)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP