而不是:
SELECT Customer,SUM(OrderPrice) FROM Orders
GROUP BY Customer
如何通过子查询生成COUNT来获得上述内容。
SELECT Customer,Count(select * from Orders where o.idUser = u.idUser) FROM Orders o
inner join Users u on u.idOrder = o.idOrder
GROUP BY Customer
THX
答案 0 :(得分:0)
这应该这样做,我认为不需要在Topquery中包含Orders:
SELECT u.Customer, (SELECT COUNT(*) FROM Orders o WHERE o.idUser = u.idUser)
FROM Users u