SQLite MIN()函數

SQLite MIN()函數用於獲取表達式或給定列的最小值。

語法

SELECT MIN(aggregate_expression)  
FROM tables  
[WHERE conditions];

GROUP BY子句中使用Min()函數時的語法:

SELECT expression1, expression2, ... expression_n  
MIN(aggregate_expression)  
FROM tables  
[WHERE conditions]  
GROUP BY expression1, expression2, ... expression_n;

示例1:

假設有一個名爲student的表,具有以下數據:

SQLite

student表中檢索學生的最低費用(fees):

SELECT MIN(FEES) AS "Lowest Fees"  FROM STUDENT; 

-- 最小年齡
SELECT MIN(age) AS "Lowest age"  FROM STUDENT;

執行上面查詢代碼,得到以下結果 -

sqlite> SELECT MIN(FEES) AS "Lowest Fees"  FROM STUDENT;
2000.0
sqlite>
sqlite> SELECT MIN(FEES) AS "Lowest Fees"  FROM STUDENT;
2000.0
sqlite>
sqlite> -- 最小年齡
sqlite> SELECT MIN(age) AS "Lowest age"  FROM STUDENT;
21
sqlite>

示例2:

使用具有的GROUP BY子句的MIN()函數:

student表中檢索NAMEMIN FEES,並按NAME的數據排序:

SELECT NAME, MIN(FEES) AS "Lowest Fees"  
FROM STUDENT  
WHERE ID <= 8  
GROUP BY NAME;

執行上面代碼,得到以下結果 -

sqlite> SELECT NAME, MIN(FEES) AS "Lowest Fees"
   ...> FROM STUDENT
   ...> WHERE ID <= 8
   ...> GROUP BY NAME;
Avgsu|2000.0
Javasu|18000.0
Linsu|10000.0
Maxsu|20000.0
Minsu|5000.0
Sqlsu|25000.0
sqlite>