postgresql group by count condition