假设我有一个名为“REVIEWS”的表
此表包含客户为各种产品撰写的评论。
我希望能够对每个客户撰写的所有评论进行“计数”, 所以我写:
SELECT count(*) AS counter
FROM reviews
WHERE customers_id = 12345
现在,我的问题是我希望有一个像上面那样的计数,但只针对写了特定产品评论的客户
例如,
SELECT customers_review
FROM reviews
WHERE
products_id = '170'
总而言之,我希望能够获得客户撰写的每条评论的总计数,但仅限于为特定产品撰写评论的客户。
最佳答案
select customers_id, count(*)
from reviews
where customers_id in
(select customers_id from reviews where products_id = '170')
group by customers_id;
关于SQL 查询 : count for all the reviews that each customer has written,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1051109/