The GROUP BY statement in MySQL is used to group data by specified columns and calculate aggregate values for each group, such as totals, sums, and averages.
The statement used for grouping in MySQL: GROUP BY
The GROUP BY statement in MySQL is used to group data Group by specified columns and calculate aggregate values for each group such as SUM, COUNT, AVG, etc.
Syntax:
<code class="sql">SELECT 列名1, 列名2, ... FROM 表名 GROUP BY 分组列 HAVING 条件(可选)</code>
Parameters:
How it works:
The GROUP BY statement groups the data in the table by the grouping column and creates a new result set with each group There is only one line. The aggregate value for each group is calculated based on the corresponding values for that group in the original data.Example:
Suppose we have a table named "sales" that contains the following data:Product Name | Sales | |
---|---|---|
100 | 2 | |
50 | 3 | |
75 | 4 | |
25 |
Result:
banana | |
The above is the detailed content of What is the statement used to group in mysql. For more information, please follow other related articles on the PHP Chinese website!