I have a table “countries” which contains population data of countries. There are 5 distinct “region_id”s – 10,20,30,40,50
I have this query:
select name, region_id,
sum(population) over (partition by region_id) as tot_pop
from countries
When I run the query, the rows are returned in the ascending order of “region_id” – in the order 10, 20, 30, 40, 50. Is this beacuse I said “partition by region_id”? So does partition by column_name sort the column_name or am I getting the result this way because the rows themselves were inserted in ascending order of region_id into the table?