How to group queries

The group by syntax is as follows:

group by field name [having conditional expression] [with rollup] ;

(1) Field name: Refers to grouping according to the value of the field, and specifies that multiple fields are separated by commas (,);

(2) having conditional expression: an optional parameter, used to limit the display after grouping, and the results that satisfy the conditional expression will be displayed.

(3) wirh rollup: optional parameter. A record will be added at the end of all records, which is the loyalty and harmony of all the records above.

(4) group by queries the grouping of field values.

Generally, group by is used when sum(), count(), avg() are used in aggregate functions.

 

The difference between having and where:

1 having is for the result group, where is for the column data.

2 having can be used with aggregate functions, where cannot.

3 The having statement only filters the grouped data, and where filters the data before the grouping.

Example:

select nameid from article group by nameid; // Only one record can be found

select concat(nameid)from article group by nameid; //Group by article number nameid. concat(nameid) displays all article ID columns

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325070769&siteId=291194637
Recommended