2012-01-15 46 views
1

我認爲我已經達到了與左聯接的最新限制。目前,我有以下MySQL查詢這是工作的罰款:左加入,用PHP和MySQL計算簡單的博客腳本

SELECT blog.id, blog.title, blog.post, blog.date, blog.time, 
     count(blog_comment.b_id) CommCount 
FROM blog 
LEFT JOIN blog_comment ON blog.id = blog_comment.b_id 
GROUP BY blog.id 
ORDER BY id DESC 
LIMIT $start_blog, $blog_per_page 

這將顯示博客文章列表和顯示評論每篇文章都有,美觀大方,簡單的數量。

對於管理面板,我想顯示博客帖子,然後顯示每個帖子上的評論數量,然後顯示一個顯示待處理評論數量的新字段。

將提出的意見都存儲在blog_comment.pending(1爲不等待等待,0)

我剛纔似乎無法讓我的周圍如何做到這一點的頭。

回答

1

試試這個:

SELECT blog.id, blog.title, blog.post, blog.date, blog.time, 
     count(blog_comment.b_id) CommCount, 
     sum(blog_comment.pending) PendingComments 
FROM blog 
LEFT JOIN blog_comment ON blog.id = blog_comment.b_id 
GROUP by blog.id 
ORDER BY id DESC LIMIT $start_blog , $blog_per_page 

總和將簡單地添加了一些未決標誌...

+0

太感謝你了,那只是對我是什麼之後罰單。 – TheVDM 2012-01-15 18:20:37