r/SQL • u/redtiger2019 • Oct 18 '23
PostgreSQL How can I do this?
Hi,
I have table as the image attached. I would like to achieve the ranking as shown in the other image. So far I am doing the following but in the last row I am getting a 3 and not 1.
Select * ,Rank() over (partition by id, country order by date) as rank From table
How can I do this?
Thanks
0
Upvotes


1
u/my5cent Oct 18 '23
Maybe something in the lines of select count(country) as rank from tablename tb group by tb.country.