I have a table where I want to find the max value of an array per distinct values in column. I've been trying to use a window function but it says i need to use group by on my unnested value.
listed_in_city | rest_type
-----------------------+-----------
Koramangala 5th Block | {Cafe}
Koramangala 5th Block | {Cafe}
Koramangala 5th Block | {Cafe}
Koramangala 5th Block | {Cafe}
Koramangala 5th Block | {Cafe}
(5 rows)
i tried using window function like this:
select listed_in_city, max(element) OVER(PARTITION)
FROM (
select unnest(rest_type) as element, listed_in_city FROM zomato
) a
group by listed_in_city
;
but gives me error:
ERROR: column "a.element" must appear in the GROUP BY clause or be used in an aggregate function
Thank you