Skip to content
Advertisement

How to deal with JSON column while using GROUP BY

I’m using a query similar to the below one, address is JSON TYPE.

But getting below error:

I’m trying to get the data of a person who has the max salary for his age and I need to include adress filed which should be JSON

So, Is the there any way to achieve this or is this practically possible ?

Note:- postgres db

Advertisement

Answer

I’d go with DISTINCT ON() instead:

The DISTINCT ON (age) will give you one row for each age. The one with the highest salary, as the ORDER BY decides.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement