The field specified in the select must be included in the Group By statement as the basis for grouping; or it must be included in the aggregate function.
The field of conditional judgment after having must be the result returned by the aggregate function,