Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下表格:
fss_post(post_id,text) fss_comment(idComment, post_id, text)
是否可以编写一个查询,为每个 post_id 提供一行以及该帖子的总评论数?
例子:
post_id comment_count 101010 5 101011 0
等等...谢谢。
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
试试这个:选择 post_id, COUNT(comment_id) from comments GROUP BY post_id;