GROUP BY and Aggregate Operations
For aggregate operations, including SUM, AVERAGE, MAX, MIN, and COUNT, GROUP BY can be used to return a summary row for each group.
Aggregate operators can be used only in the SELECT expression list or in the optional HAVING clause.