SQL List按降序排列的总订单

时间:2013-05-04 05:11:58

标签: sql ms-access syntax

SELECT Customer.CID, Count(Order.OrderID) AS [# Orders]
FROM Customer INNER JOIN [Order] ON Customer.CID = Order.CID
Group By Customer.CID DESC;

我试图按降序列出客户的订单总数。我在group by子句中遇到语法错误。我不确定语法错误是什么。

2 个答案:

答案 0 :(得分:3)

你错过了你的ORDER BY子句。您的查询应如下所示:

SELECT Customer.CID, Count(Order.OrderID) AS [# Orders]
FROM Customer INNER JOIN [Order] ON Customer.CID = Order.CID
GROUP BY Customer.CID
ORDER BY Customer.CID DESC;

答案 1 :(得分:1)

您应该使用order by代替group by 所以你的新查询将是,

SELECT Customer.CID, Count(Order.OrderID) AS [# Orders]
FROM Customer INNER JOIN [Order] ON Customer.CID = Order.CID
Order By Customer.CID DESC;

我没有桌子。所以请提供你的评论。