我在试着在“帖子”表上统计帖子数量,
i have id,topic_id (topic_id= the topic id)在“主题”表中,
i have id,f_id (f_id= the forum id )我试着边做边做,但不知道怎么算这些帖子?前任:
<php?
$test2=mysql_query("SELECT *, COUNT(topic_id) AS post_count FROM posts t LEFT JOIN topics p ON p.id = t.id WHERE `f_id`='1' GROUP BY t.id") or die (mysql_error());
?>发布于 2014-04-02 23:00:59
请尝试以下查询:
SELECT *, COUNT(topic_id) AS post_count
FROM posts t
LEFT JOIN topics p
ON p.id = t.id AND `f_id`='1'
GROUP BY t.idhttps://stackoverflow.com/questions/22821841
复制相似问题