SELECT vendor_name, COUNT(*) AS number_of_invoices, MAX(invoice_total - payment_
ID: 670951 • Letter: S
Question
SELECT vendor_name, COUNT(*) AS number_of_invoices, MAX(invoice_total - payment_total - credit_total) AS balance_due FROM vendors v JOIN invoices i ON v.vendor_id = i.vendor_id WHERE invoice_total - payment_total - credit_total > (SELECT AVG(invoice_total - payment_total - credit_total) FROM invoices) GROUP BY vendor_name ORDER BY balance_due DESC A.1 B. of invoices in the Invoices table C.of invoices for each vendor D. of invoices for each vendor that have a larger balance due than the average balance due for all invoices
Explanation / Answer
This query will return one row for each vendor that shows the largest balance due for any of the vendor’s invoices, but only if that balance due is larger than the average balance due for all invoices.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.