SQL 最小值()
SQL MIN() Function
#MIN() 函數
MIN() 函數傳回指定列的最小值。
SQL MIN() 語法
SELECT MIN(column_name) FROM table_name;
示範資料庫
在本教學中,我們將使用php 樣本資料庫。
下面是選自"Websites" 表的資料:
+----+--------------+--- ------------------------+-------+---------+
| id | name | url | alexa | country |
+----+----------+------------------------------------ --------+-------+---------+
| 1 | Google | https://www.google.cm/ | 1 | USA | 1 |
| 2 | 淘寶 | https://www.taobao.com/ | 13 | CN cn/ | 4689 | CN |
| 4 | 微博 | http://weibo.com/ | 20 ://www.facebook.com/ | 3 | USA |
| 6 | 百度| https://www.baidu.com/ | 4 | CN |
| 7 | stackoverflow | http://stackoverflow.com/ | 0 | IND |
+----+---- -----------+-----------------------------------------+-------+-- -------+
| id | name | url | alexa | country |
+----+----------+------------------------------------ --------+-------+---------+
| 1 | Google | https://www.google.cm/ | 1 | USA | 1 |
| 2 | 淘寶 | https://www.taobao.com/ | 13 | CN cn/ | 4689 | CN |
| 4 | 微博 | http://weibo.com/ | 20 ://www.facebook.com/ | 3 | USA |
| 6 | 百度| https://www.baidu.com/ | 4 | CN |
| 7 | stackoverflow | http://stackoverflow.com/ | 0 | IND |
+----+---- -----------+-----------------------------------------+-------+-- -------+
下面的SQL 語句從"Websites" 表的"alexa" 欄位取得最小值:
範例SELECT MIN(alexa) AS min_alexa FROM Websites;
執行上述 SQL 結果如下圖所示: