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 子句上遇到语法错误。我不确定语法错误是什么。
您缺少 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;
您应该使用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;
我没有桌子。所以请提供你的评论。