Home  >  Article  >  Database  >  MySQL statistical minimum data Select Min

MySQL statistical minimum data Select Min

黄舟
黄舟Original
2016-12-27 17:32:062241browse

Statistical minimum data

SELECT MIN() FROM syntax is used to count the minimum data of a field from the data table.

Syntax:

SELECT MIN(column) FROM tb_name

Please refer to MAX() for specific usage.

Explanation

The above statistical queries including ordinary field queries can be mixed:

SELECT MAX(uid) as max,MIN(uid)as min,AVG(uid) as avg FROM user

The query results are as follows:

MySQL statistical minimum data Select Min

But it should be noted that the results of statistical queries and ordinary field queries are often not what is expected. For example, if you want to query the user name with the largest uid (including uid):

//这种写法是错误的,尽管能执行
SELECT MAX(uid),username FROM user
//这种写法是正确的
SELECT uid,username FROM user ORDER BY uid DESC LIMIT 1

The above is the content of the MySQL statistical minimum data Select Min. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:MySQL Where conditionNext article:MySQL Where condition