First page Back Continue Last page Image
Highlight the Relationship Between GROUP BY and HAVING
SELECT vendor_state, vendor_city, COUNT(*) AS invoice_qty,
ROUND(AVG(invoice_total), 2) AS invoice_avg
FROM invoices JOIN vendors
ON invoices.vendor_id = vendors.vendor_id
GROUP BY vendor_state, vendor_city
HAVING COUNT(*) >= 2
ORDER BY vendor_state, vendor_city
The HAVING clause is like a WHERE clause but just for the GROUP, You need a GROUP BY Clause to use a HAVING Clause
Group the records by City but only include in the output if a city has 2 or more invoices associated with it
Perhaps I am paying allot for delivery so I want to analyze where I am buying stuff from