我正在努力计算帖子数量 在“帖子”表中,
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());
?>
答案 0 :(得分:0)
尝试此查询:
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.id