In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you what the function of mysql is to find the maximum, minimum and average values. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
In mysql, you can use the MAX () function, the MIN () function, and the AVG () function to find the maximum, minimum, and average, respectively. The MAX () and MIN () functions return the maximum and minimum values in a specified column; the AVG () function calculates the average of the data in the specified column by calculating the number of rows returned and the sum of each row of data.
MySQL MAX function: query the maximum value of a specified column
The MySQL MAX () function is used to return the maximum value in the specified column.
To make it easier to understand, first create a student score sheet tb_students_score, the data contents of which are shown below.
Mysql > use test_db;Database changedmysql > SELECT * FROM tb_students_score +-+-+ | student_name | student_score | +-+-+ | Dany | 90 | | Green | 99 | Henry | 95 | Jane | 98 | | Jim | 88 | John | 94 | Lily | 100 | Susan | 96 | Thomas | 93 | Tom | 89 | +-+-+ 10 rows in set (0.13 sec) |
[example 1] find the highest score in the tb_students_score table, enter the SQL statement and the execution result is shown below.
Mysql > SELECT MAX (student_score)-> AS max_score-> FROM tb_students_score;+-+ | max_score | +-+ | 100 | +-+ 1 row in set (0.06 sec)
As you can see from the running results, the maximum value of the student_score field queried by the MAX () function is 100.
The MAX () function applies not only to finding numeric types, but also to character types.
[example 2] look for the maximum value of student_name in the tb_students_score table, and the SQL statement entered and the execution result are shown below.
Mysql > SELECT MAX (student_name)-> AS max_name-> FROM tb_students_score;+-+ | max_name | +-+ | Tom | +-+ 1 row in set (0.03 sec)
As you can see from the running results, the MAX () function determines the size of the letters and returns the largest character or string value.
Note: the MAX () function can also return the maximum value in any column, including the maximum value of the character type. When comparing the data of character types, according to the value of the ASCII code of the character, the ASCII code of a character is the smallest and the ASCII code of z is the largest. When comparing, first compare the first character, and if equal, continue to compare the next character until the two characters are not equal or until the end of the character. For example, when b is compared to t, t is the maximum; when bcd is compared with bca, bcd is the maximum.
MySQL MIN function: query the minimum value of a specified column
The MySQL MIN () function is used to return the minimum value in the query column.
[example] find the lowest score in the tb_students_score table, enter the SQL statement and the execution result is shown below.
Mysql > SELECT MIN (student_score)-> AS min_score-> FROM tb_students_score;+-+ | min_score | +-+ | 88 | +-+ 1 row in set (0.00 sec)
As you can see from the result, the minimum value of the student_score field queried by the MIN () function is 88.
Tip: the MIN () function is similar to the MAX () function in that it applies not only to finding numeric types, but also to character types.
MySQL AVG function: find the average
The MySQL AVG () function calculates the average of the specified column data by calculating the number of rows returned and the sum of each row of data.
[example] in the tb_students_score table, the average scores of all students are queried. The SQL statement entered and the execution results are shown below.
Mysql > SELECT AVG (student_score)-> AS score_avg-> FROM tb_students_score;+-+ | score_avg | +-+ | 94.2000 | +-+ 1 row in set (0.03 sec)
Tip: when using the AVG () function, the argument is the name of the column to be calculated, and to get the average of multiple columns, you need to use the AVG () function on each column.
Thank you for reading! On the mysql to find the maximum, minimum and average function is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.