First page Back Continue Last page Image

Doing a Summary function on a Group

SELECT vendor_id, ROUND(AVG(invoice_total), 2) AS average_invoice_amount

FROM invoices

GROUP BY vendor_id

HAVING AVG(invoice_total) > 2000

ORDER BY average_invoice_amount DESC

Let’s say we want to know which Vendors I buy stuff from the most, we could average the invoice amounts for each Vendor and then compare them

The Output for this Query

This first part is doing the same Average and Rounding we saw in a previous example

This Argument is grouping by Vendor

The Having clause was used here because I only want to see my Vendors I Pay allot too

Then I used my initial data return target to sort the data with the ORDER BY and DESC