I am trying to run this query in postgresql but getting this error: "ERROR: Aggregate function calls may not be nested". I am not sure what the problem or a solution for this.
Here is my query:
select a.KEY_NBR, a.MAIN_ID
,
case
when a.KEY_NBR = a.MAIN_ID
then 'Don''t Use'
when a.count = MAX(a.count) over(partition by a.KEY_NBR)
then 'Good'
else 'Bad'
end [flag]
from MYTABLE a