CusID Order
3001 Hotdog
3001 Sausage
3002 Sausage
3003 Burger
3003 Hotdog
3002 Hotdog
3001 Burger
我将如何使用此计数功能?
SELECT COUNT(CusID) AS NumOfOrders FROM Orders
所需的输出
CusID NumOfOrders
3001 3
3002 2
3003 2
最佳答案
您需要使用group by
:
SELECT CusId, COUNT(CusID) AS NumOfOrders
FROM Orders
group by CusId
order by CusId;
关于sql - SQL计数功能按列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17778793/