MySQL aggregate functions are commonly used with five SUM COUNT AVG Min/max
AVG ([DISTINCT] expr)
Returns the average of expr. The DISTINCT option can be used to return the average of different values of expr.
SELECT Gender, AVG (age) from student
GROUP by gender;
COUNT (expr)
Returns the number of non-null values in the row retrieved by the SELECT statement.
SELECT COUNT (*) from student; --Returns the number of rows retrieved, regardless of whether they contain null values
SELECT COUNT (name) from student; --Returns the non-null value of the row retrieved by the SELECT statement
The number
MIN ([DISTINCT] expr), MAX ([DISTINCT] expr)
Returns the minimum and maximum values for expr
SELECT MIN (age), MAX (age) from student;
SUM ([DISTINCT] expr)
Returns the total number of expr
SELECT SUM (age) from student;
This article is from "Yun Weibang" blog, please be sure to keep this source http://aklaus.blog.51cto.com/9724632/1597527
MySQL aggregate function