I'm getting error with a query and would really appreciate some help.
I have to Create a view named TOP10PaidInvoices that returns three columns for each vendor: VendorName, LastInvoice (the most recent invoice date), and SumOfInvoices (the sum of the InvoiceTotal column). Return only the 10 vendors with the largest SumOfInvoices and include only paid invoices.
Here is my statement but I get some errors. Would like to know what is wrong with it.
CREATE VIEW TOP10PaidInvoices
SELECT TOP 10 Vendors.VendorName, Invoices.LastInvoice AS InvoiceDate,
Invoices.SumOfInvoice AS InvoiceTotal,
FROM Invoices INNER JOIN Vendors ON Invoices.InvoiceID = Vendors.VendorID
ORDER BY SumOfInvoices ASC
Here are the errors I am getting
Msg 8120, Level 16, State 1, Procedure TOP10PaidInvoices, Line 2
Column 'Vendors.VendorName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 207, Level 16, State 1, Procedure TOP10PaidInvoices, Line 2
Invalid column name 'LastInvoices'.
Msg 207, Level 16, State 1, Procedure TOP10PaidInvoices, Line 3
Invalid column name 'SumOfInvoices'