SQLite MIN()函数

编辑时间: 2018-02-07 12:51:56    关键字:

 SQLite MIN()函数用于获取表达式或给定列的最小值。

语法

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

GROUP BY子句中使用Min()函数时的语法:

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

示例1:

假设有一个名为student的表,具有以下数据:

student表中检索学生的最低费用(fees):

SELECT MIN(FEES) AS "Lowest Fees"  FROM STUDENT;   -- 最小年龄 SELECT MIN(age) AS "Lowest age"  FROM STUDENT; 
SQL

执行上面查询代码,得到以下结果 -

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> 
SQL

示例2:

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

student表中检索NAMEMIN FEES,并按NAME的数据排序:

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

执行上面代码,得到以下结果 -

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> 
SQL

推荐热图

合作推荐

2010-2018 可思数据版权所有 About SYKV | ICP备案:京ICP备14056871号