开发者

Using a subquery in an aggregate expression

Instead of this:

SELECT Customer,SUM(OrderPrice) FROM Orders
GROUP BY Customer

How do I get something like above but by producing a COUNT fr开发者_运维知识库om a subquery.

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


This should do, I see no need to include Orders in the Topquery:

SELECT u.Customer, (SELECT COUNT(*) FROM Orders o WHERE o.idUser = u.idUser)
FROM Users u
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜