By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
| version() |
|---|
| 8.0.36 |
Records: 5 Duplicates: 0 Warnings: 0
| country | city | population | rn |
|---|---|---|---|
| Italy | Rome | 2000000 | 1 |
| Italy | Milano | 1000000 | 2 |
| Italy | Bologna | 800000 | 3 |
| Poland | Warszawa | 1000000 | 1 |
| Poland | Wroclaw | 700000 | 2 |
| country | city | population |
|---|---|---|
| Italy | Rome | 2000000 |
| Poland | Warszawa | 1000000 |
| EXPLAIN |
|---|
| -> Sort: pops.country (cost=0.45..0.45 rows=0) -> Index lookup on pops using <auto_key0> (rn=1) (cost=0.35..0.35 rows=1) -> Materialize (cost=0..0 rows=0) -> Window aggregate: row_number() OVER (PARTITION BY cities.country ORDER BY cities.country,cities.population desc ) -> Sort: cities.country, cities.country, cities.population DESC (cost=0.75 rows=5) -> Index scan on cities using cities_city_ix (cost=0.75 rows=5) |