Filtering groups with HAVING
• The HAVING clause is a filter that acts like a WHERE clause, but on groups of rows rather than on individual rows.
SELECT column_name(s)
FROM table_name0
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
EXAMPLE:
SELECT Salesperson, SUM(TotalSale)
FROM SALES
GROUP BY Salesperson
HAVING Salesperson <>'Bennett';
SQL statement lists the number of customers in each country, sorted high to low:
SELECT COUNT (CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT (CustomerID) > 5
ORDER BY COUNT (CustomerID) DESC;