目标
数一数市场有多少产品。
问题
查询只返回第一个结果,我想要inMarketsQuantity
每个产品的结果。
场景
这是查询:
Select product.Name As productName,
Count(marketProducts.ProductId) As inMarketsQuantity
From products As product
Join market_products As marketProducts On product.Id = marketProducts.ProductId
Join markets As market On marketProducts.MarketId = market.Id
这是结果:
+---------------+-------------------+
| productName | inMarketsQuantity |
+---------------+-------------------+
| Playstation 3 | 15 |
+---------------+-------------------+
这就是我所期待的:
+---------------+-------------------+
| productName | inMarketsQuantity |
+---------------+-------------------+
| Playstation 3 | 10 |
+---------------+-------------------+
| Xbox | 5 |
+---------------+-------------------+
我已经尝试过的
我已经尝试过以下查询,但我收到了SQL 错误 (1064):
Select product.Name As productName,
Distinct(Count(marketProducts.ProductId)) As inMarketsQuantity
[...]