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!