0
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 子句上遇到语法错误。我不确定语法错误是什么。

4

2 回答 2

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;
于 2013-05-04T05:24:19.540 回答
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;

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

于 2013-05-04T05:29:53.463 回答