Skip to content
Advertisement

SQL find the 2 highest score for each country

I have two tables: maps_query and map_time like below:

The question is to find the 2 highest score for each country. Desired output is like below:

I was trying to use row_number() over but don’t know how to complete the query.

Advertisement

Answer

This can be achieved by rank() instead of row_number().

A good reference article: https://spin.atomicobject.com/2016/03/12/select-top-n-per-group-postgresql/

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