我希望COUNT(*)
Offer
表中有Product
表中有多少行,如果Product.Producer
表格中的123
表中有Offer.PricePolicy
列等于31
且# | ID
----------
1 | 1277
2 | 1279
2 | 1280
列为3
。
此查询返回3个结果:
SELECT Product.ID
FROM Offer
LEFT JOIN Product ON Offer.ID = Product.ID
WHERE Product.Producer = 123
AND Offer.PricePolicy = 31
GROUP BY Product.ID
如何修改它以返回结果数?
预期结果为{{1}}
{{1}}
答案 0 :(得分:1)
只需将COUNT(*)
添加到SELECT
:
SELECT Product.ID, COUNT(*)
FROM Offer
LEFT JOIN Product ON Offer.ID = Product.ID
WHERE Product.Producer = 123
AND Offer.PricePolicy = 31
GROUP BY Product.ID
如果您不需要Product.ID
,则投影中也只能有COUNT(*)
。