我遇到了一些問題....我如何獲得下面的代碼以返回下面的表作爲客戶總和?我想要客戶提供的總客戶數量,然後是前10名。所以所有的黃玫瑰應該加在一起,然後算作一個入口,而不是單獨出現所有的貨物。客戶排名前10位 - 總計
select top 10 T1.Quantity, T1.CustName
from
(
select
SUM(Tkscale.Qty)Quantity,
Slcust.Name CustName
from Tkscale with (nolock)
left outer join Slcust with (nolock) on Tkscale.CustomerID = Slcust.CustomerID
group by Tkscale.CustomerID, Tkscale.Qty, Slcust.Name
) T1
order by T1.CustName desc, T1.Quantity desc
2008 R2 @CodeDifferent – Molly
在內部查詢通過tkscale.qty不羣。這是總結,所以它不應該在組中。 – xQbert
在繼續使用nolock提示丟棄數據庫之前,您可能需要閱讀本文。 http://blogs.sqlsentry.com/aaronbertrand/bad-habits-nolock-everywhere/ –