SELECT COUNT(*) AS posts, post.userid FROM post LEFT JOIN user ON post.userid = user.userid WHERE user.usergroupid IN (10, 62) AND visible = 1 AND dateline BETWEEN UNIX_TIMESTAMP( '2015-06-30') AND UNIX_TIMESTAMP( '2015-10-01') GROUP BY post.userid ORDER BY posts DESC