Improving grouped count query for MySQL