Summary data Sometimes the operation of the data table is not the data in the table itself, but a summary of the data in the table, such as the average value of a column of data, maximum, minimum, and so on. For these commonly used data aggregation processes, MySQL provides functions to handle.
SQL aggregation functions
Function |
Description |
COUNT () |
Returns the number of rows in a column |
MAX () |
Returns the maximum value of a column |
MIN () |
Returns the minimum value of a column |
AVG () |
Returns the average of a column |
SUM () |
Returns the sum of a column value |
Example:
First, the Products table is shown below:
Find the average of the Prod_price column looks strange, the original table shows only one line:
To find out the price of all goods of a particular line, such as vend_id =1003;
The Count function is used to determine the number of rows that satisfy a certain condition, with a total of 14 rows in the Products table:
Statistics VEND_ID = 1001 has how many lines:
Max () Find maximum value
Min () Min value
SUM () sums of the sequence values
Aggregating different values counts how many vendors, plus the DISTINCT keyword, only counts the number of different values in that column:
Combining aggregate functions Multiple functions can be used together, more powerful: