sql where group attention points

select column a, aggregate function from table name where filter condition group by column a having filter condition

The group by clause is also used in conjunction with the where conditional statement. When combined, where comes first and group by comes after. That is, first filter the record set of select xx from xx with where, and then use group by to group the filtered results and use the having clause to filter the grouped results

Need to pay attention to the difference between the usage of having and where:

1.Having can only be used after group by to filter the grouped results (that is, the precondition for using having is grouping).

2.where must be before group by

3. Aggregate functions are not allowed in the conditional expression after where, but having can.

Guess you like

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