/* Group By with Having */ /* the Having filter the output AFTER the Group By has completed */ SELECT vendor, SUM(amount), COUNT(amount) FROM payment GROUP BY vendor HAVING SUM(amount) > 150; /* The Where clause filters BEFORE the Group By */ /* The Having clause filter the output AFTER the Group By */ SELECT vendor, sum(amount) total FROM payment WHERE description <> 'Home Insurance' GROUP BY vendor HAVING sum(amount) > 150; SELECT vendor, sum(amount) total, count(vendor) tally FROM payment WHERE amount > 50 GROUP BY vendor HAVING sum(amount) > 250; /* OR count(vendor) > 2 */