First page Back Continue Last page Image
Using COUNT with DISTINCT to get more information
SELECT COUNT(DISTINCT vendor_id) AS number_of_vendors,
COUNT(vendor_id) AS number_of_invoices,
ROUND(AVG(invoice_total), 2) AS avg_invoice_amt,
SUM(invoice_total) AS total_invoice_amt
FROM invoices
WHERE invoice_date > '2018-01-01'
In this example I want to know more than just how many unpaid bills I owe, I also want to know how many vendors I am dealing with
By Adding DISTINCT here I will get the number of Vendors who have invoices in the invoice table
The Output for this Query