GROUP BY — aggregate rows by column. HAVING — filter groups.
Example:
1-- Total sales by country2SELECT country, SUM(amount) as total_sales3FROM orders4GROUP BY country;56-- Countries with sales over $10,0007SELECT country, SUM(amount) as total_sales8FROM orders9GROUP BY country10HAVING SUM(amount) > 10000;
Aggregate functions:
Difference: