Group by

GROUP BY

Example:

SELECT BillingCity, COUNT(*), MAX(InvoiceDate) FROM invoices GROUP BY BillingCity;

**In a GROUP BY select, you can only use aggregate functions and the column being grouped by (which makes logical sense)

Syntax:

NOTE!!! Do not confuse GROUP BY and ORDER BY The latter is sorting, for example by ascending numbers or alphabetically, while the former is grouping by a certain common parameter

**Grouping by TWO parameters:

In GROUP BY there is the HAVING keyword which allows

filtering using aggregate functions (WHERE cannot do this)

Example WITHOUT and WITH HAVING: