我有以下表格:
fss_post(post_id,text)
fss_comment(idComment, post_id, text)
是否可以编写一个查询,为每个post_id提供一行,并为此帖子提供总评论数?
实施例
post_id comment_count
101010 5
101011 0
依旧...... 感谢。
答案 0 :(得分:3)
select
p.post_id,count(*) 'comment_count'
from
fss_post p
left join fss_comment c on p.post_id = c.post_id
group by p.post_id
答案 1 :(得分:0)
试试这个: 从评论GROUP BY post_id;
中选择post_id,COUNT(comment_id)