HanseNautic

 
SELECT `main_table`.*, COUNT(IF(comments_table.status = 2,comments_table.post_id, NULL)) AS `comment_count` FROM `aw_blog` AS `main_table` LEFT JOIN `aw_blog_store` AS `store_table` ON main_table.post_id = store_table.post_id LEFT JOIN `aw_blog_comment` AS `comments_table` ON main_table.post_id = comments_table.post_id WHERE (main_table.created_time<='2017-01-22 20:12:17') AND (main_table.status = 1) AND (store_table.store_id in (0, '2')) GROUP BY `main_table`.`post_id` ORDER BY created_time DESC LIMIT 5