Grouping function and grouping query

count counts the number of rows that are not empty

 

If you want to query the status of each department, you need to query each department separately. The following figure is very troublesome, so there is a group query

The grouping function is generally used with grouping query;

 

The above writing is wrong, because where is executed before select, he does not know count(*)

HAVING for screening after grouping

The filtering before grouping is that the filtering conditions are before grouping groupby. At this time, he only knows the original columns

In order to distinguish between filtering before grouping and after grouping, use where before grouping and having after grouping

Summary: The order of execution must be clear!

 

Guess you like

Origin blog.csdn.net/m0_37839403/article/details/113856731