Postgresql Json Build Object Group By And Having In Sql