Code example 7-2
SELECT i.vendor_id, MAX(i.invoice_total) AS largest_invoice
FROM invoices i
JOIN
(SELECT vendor_id, AVG(invoice_total) AS average_invoice
FROM invoices
GROUP BY vendor_id
HAVING AVG(invoice_total) > 100
ORDER BY average_invoice DESC) ia
ON i.vendor_id = ia.vendor_id
GROUP BY i.vendor_id
ORDER BY largest_invoice DESC
(Please refer to code example 7-2.) When this query is executed, each row in the result table will show
the largest invoice total related to that row, but only if it's larger than the average for all invoices
the largest invoice total related to that row
the average invoice total related to that row, but only if it's greater than 100
the average invoice total related to that row