group by having postgresql