Statistical average
the SELECT AVG () from syntax is used to average statistics from data tables.
Grammar:
SELECT AVG (column) from Tb_name
This SQL syntax is used to count the average of a numeric type field, and the AVG () cannot be more than one field, and the type of string can be executed but meaningless.
Example:
SELECT AVG (UID) from user
Get the result of the query:
Of course, the average of this statistic uid is meaningless, just to demonstrate the usage of AVG () syntax.
The sum of statistical data
the SELECT SUM () from syntax is used to sum the data from the data table.
Grammar:
SELECT SUM (column) from Tb_name
This SQL syntax is used to count the sum of the values of a numeric Type field, and the SUM () cannot be more than one field, while a type such as a string can be executed but meaningless.
Example:
SELECT SUM (UID) from user
Get the result of the query:
Copy Code code as follows:
10
Statistics Maximum data
the SELECT max () from syntax is used to count a field's maximum data from a datasheet.
Grammar:
SELECT MAX (column) from Tb_name
This SQL syntax is used to count the maximum value of a numeric Type field and cannot be more than one field in MAX ().
Example:
SELECT MAX (UID) from user
Get the result of the query:
Statistic Minimum Data
the SELECT min () from syntax is used to count a field's minimum data from a datasheet.
Grammar:
SELECT MIN (column) from Tb_name
Please refer to MAX () for specific usage.
Description
The above statistical query includes common field query can be mixed use:
SELECT MAX (UID) as Max,min (UID) as MIN,AVG (UID) as AVG from user
The results of the query are as follows:
However, you need to pay attention to the statistical query and normal field query when the results are often not expected. For example, to query the maximum user name (including UID) for the UID:
This is a wrong notation, although it is possible to execute
select MAX (UID), username
from user///This is the correct type of
select Uid,username from user order by UID DESC LIMIT 1