postgres group by count with condition