SELECT `main_table`.*, `comments_select`.`comment_count` FROM `aw_blog` AS `main_table` LEFT JOIN (SELECT `aw_blog_comment`.`post_id`, COUNT(IF(status = 2, post_id, NULL)) AS `comment_count` FROM `aw_blog_comment` GROUP BY `post_id`) AS `comments_select` ON main_table.post_id = comments_select.post_id WHERE (main_table.created_time<='2018-10-21 09:44:12') AND (main_table.status = 1)