GROUP BY
and
HAVINGBy including a
GROUP BY
clause functions such asSUM
andCOUNT
are applied to groups of items sharing values. When you specifyGROUP BY continent
the result is that you get only one row for each different value ofcontinent
. All the other columns must be “aggregated” by one ofSUM
,COUNT
…The
HAVING
clause allows use to filter the groups which are displayed. TheWHERE
clause filters rows before the aggregation, theHAVING
clause filters after the aggregation.
- where 过滤在前
- group by 中间
- having 过滤在后
1 | -- 1 |