所以标题非常准确,我想我快到了这就是我所拥有的
编辑:视图应该选择列供应商名称,列 LastInvoice 是列中的最新日期和 invoiceTotal 列的总计。我希望它只显示前 10 个已支付的 invoiceTotals 以及相应的最新发票日期和供应商名称。
CREATE VIEW TOP10PAIDInvoices
AS
SELECT VendorName,
MAX(InvoiceDate) AS LastInvoice,
SUM(InvoiceTotal) AS SumOfInvoices
FROM Vendors
JOIN Invoices
ON Vendors.VendorID = Invoices.VendorID
WHERE (SELECT TOP 10 SumOfInvoices
FROM TOP10PAIDInvoices
GROUP BY SumOfInvoices
HAVING SumOfInvoices > 0)
ORDER BY SumOfInvoices