我已浏览论坛,可以找到各种示例来解决我的问题,但不能将所有内容放在一起。使用Group By,Top N和Sum的查询
我的情况是典型的,我希望按组(Shop_Lookup.ShopGroup))显示前10位客户(订单。[客户名称])的总收入。
无论ShopGroup如何,我都可以获得整体排名前10位的排名,但却无法让我的头部得到子查询的工作。我目前的代码是 -
SELECT TOP 10 Orders.[Customer Name],
Sum(Orders.[Actual Revenue]) AS [SumOfActual Revenue],
Orders.[This Month],
Shop_Lookup.[ShopGroup]
FROM Orders
INNER JOIN Shop_Lookup ON Orders.[ShopID] = ShopLookup.[ShopID]
WHERE ((Orders.[This Month])="current")
GROUP BY Orders.[Customer Name], Orders.[This Month], Shop_Lookup.[ShopGroup]
ORDER BY Sum(Orders.[Actual Revenue]) DESC;
好问题。如果你不能很快得到正确的答案,可以考虑添加最终结果的表示。 – Smandoli 2014-10-08 17:06:01