Home  >  Article  >  Database  >  What does group by mean in SQL?

What does group by mean in SQL?

anonymity
anonymityOriginal
2019-05-05 11:53:4935143browse

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.

What does group by mean in SQL?

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

What does group by mean in SQL?

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.

What does group by mean in SQL?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn