This question evaluates competency in SQL data manipulation, including grouped aggregation, deterministic partitioned ranking with tie-breaking, and computing percentage shares of group totals.
You are given a table world_population that contains one row per country for a single population snapshot.
Schema:
continent
STRING
country
STRING
population
BIGINT
Assumptions:
population
is non-null.
country
ascending so the ranking is deterministic.
Write SQL for the following:
continent, country, population
continent, country, population, population_rank
population_share_pct = 100 * population / total_continent_population
continent, country, population, population_rank, total_continent_population, population_share_pct