2

我需要获取帖子的数量而不是主题,其中 forum_id = 1。这甚至可能吗?我想我必须使用 join 但这对我来说似乎很难。

topics:
id | title | forum_id

posts:
id | message | topic_id
4

2 回答 2

3
SELECT COUNT(*) FROM posts JOIN topics t ON (topic_id = t.id) WHERE forum_id = 1
于 2013-06-27T00:13:59.070 回答
1

具有主题的帖子数

 select distinct count(p.id) from posts p inner join topics t on p.topic_id = t.id 
        where t.forum_id = 1
        group by p.id
于 2013-06-27T00:14:07.127 回答