464,880 views
7 votes
7 votes
Write a SELECT statement that returns a single value that represents the sum of the largest unpaid invoices submitted by each vendor. Use a derived table that returns MAX(InvoiceTotal) grouped by VendorID, filtering for invoices with a balance due

User KylePDavis
by
2.3k points

1 Answer

18 votes
18 votes

Answer:

Create table vendor(vendor_id int,due_invoice int,invoiceTotal int);

Create view v as select vendor_id,max(due_invoice) as unpaid from vendor;

Select sum(unpaid) from v;

Select vendor_id,invoiceTotal from vendor group by vendor_id;

User Sina Masnadi
by
3.0k points