Group by in SQL is to group data according to the rules specified by "By", and the so-called grouping is to divide a "data set" into several "small areas", and then target several "small areas" area" for data processing.
group_by
means which field or fields to group the data according to by. "Group By" literally means to group data according to the rules specified by "By". The so-called grouping is to divide a "data set" into several "small areas", and then target several "small areas". data processing.
Grammar structure is as follows:
select 字段 from 表名 where 条件 group by 字段 或者 select 字段 from 表名 group by 字段 having 过滤条件
Note: For filtering conditions, you can use where first, then group by or group by first, then having
Original table
Simple Group By
Example 1
select category, sum(quantity) as sum of quantities
from A
group by category
The return result is as shown in the table below, which is actually a summary of categories.
The above is the detailed content of What does group by mean in SQL?. For more information, please follow other related articles on the PHP Chinese website!