I need help with my query. I want to add a row_number to partition my fields, but I get the error:
ERROR: column "rn" does not exist
LINE 22: and rn <= 3
Do you find something strange in my query? Thanks a lot!
with location as
(select location, topcount
from pr.rankinglist_location
where topcount = 3
or (topcount = 10 and population_all > 150000)
or topcount = 25)
select store_displayname as restaurant_name,
street,
street_no,
zipcode,
city,
topcount,
ROW_NUMBER() OVER (PARTITION BY city
ORDER BY rposition DESC) rn,
store_id as store_id
from pr.rankinglist_store s
join
location m on m.location = s.city
where
statkey = '2015'
and
topcount = 3
and rn <= 3
group by 1, 2, 3, 4, 5, 6, 7, 8
order by rposition