Introduction to four aggregate functions of MySQL
This article mainly introduces the four aggregation functions of MySQL, the contents of the article are carefully selected and edited by the author, with a certain pertinence, the reference significance for you is still relatively great, the following with the author to understand the four aggregation functions of MySQL.
1.count aggregate function, which is used to count functions
(1) count the number of students in a class
Select count (*) from grade
(2) Statistics on the number of students whose math scores are greater than 70
Select count (*) from grade where math > 70
(3) the number of people whose total statistical score is greater than 230
Select count (*) from grade where chinese+math+english > 230
2.sum aggregate function to find the sum of a column that meets the condition
(1) Statistics of the total math scores of a class
Select sum (math) from grade
(2) Statistics of the total scores of Chinese, math, English and other subjects in a class.
Select sum (chinese), sum (math), sum (english) from grade
(3) Statistics of the total scores of a class in Chinese, maths, English and
Select sum (chinese+math+english) from grade
(4) Statistics of the average score of a class in Chinese.
Select sum (chinese) / count (*) from grade
3.avg aggregate function to find the average of columns that meet the condition
(1) find the average score of mathematics in a class.
Select avg (math) from grade
(2) find the average total score of a class.
Select avg (chinese+math+english) from grade
4.MAX / MIX aggregate function to find the maximum and minimum values of the columns of compound conditions
(1) seek the highest and lowest scores of the class.
Select max (chinese+math+english) from grade
Select min (chinese+math+english) from grade
After reading the above four aggregate functions about MySQL, many readers must have some understanding. If you need to get more industry knowledge and information, you can continue to follow our industry information column.