在select语句中使用TOP SQL

时间:2014-02-23 10:34:53

标签: sql

我试图只返回10行,相当于10家供应商已经获得最多报酬,但我似乎无法弄清楚如何使用TOP条款来抓住前十大供应商付出最多。

Select Top 10 SUM(PaymentTotal) AS PaymentSum, VendorName
From Invoices JOIN Vendors
On Vendors.VendorID = Invoices.VendorID
Group By VendorName;  

2 个答案:

答案 0 :(得分:1)

Select Top 10
  sum(PaymentTotal) AS PaymentSum,
  VendorName
From
  Invoices
  INNER JOIN Vendors On Vendors.VendorID = Invoices.VendorID
Group By
  VendorName
Order By
  sum(PaymentTotal) desc
;

答案 1 :(得分:0)

Select Top 10 SUM(PaymentTotal) AS PaymentSum, VendorName
From Invoices JOIN Vendors
On Vendors.VendorID = Invoices.VendorID
Group By VendorName
order by PaymentSum dsec;