Postgresql Json Build Object Group By And Having Clause