在一个示例 SQL 数据库中,我在两个单独的表中获得了 Invoice Totals 和 Vendor Names。
作为一般方向,这是我创建的当前代码:
SELECT TOP 5 InvoiceTotal, VendorName
FROM Invoices JOIN Vendors ON Invoices.VendorID = Vendors.VendorID
ORDER BY InvoiceTotal DESC;
我正在寻找不重复任何供应商名称的前 5 个发票总数。例如,我当前的输出是:
137966.19 Malloy Lithographing Inc
26881.40 Malloy Lithographing Inc
23517.58 Malloy Lithographing Inc
21842.00 Data Reproductions Corp
20551.18 Malloy Lithographing Inc
但是,目标输出类似于:
137966.19 Malloy Lithographing Inc
21842.00 Data Reproductions Corp
20076.01 Smith & Co
14590.00 Tim's Management LTD
13878.50 HelloWorld Corp
这是我可以在 Management Studio 中实现的吗?我试过实现 DISTINCT,但这似乎不起作用。
非常感谢任何帮助。