Skip to content

Instantly share code, notes, and snippets.

@allenday
Created September 17, 2021 09:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save allenday/cd1b2e27417874a7407ea5caa38f7cdb to your computer and use it in GitHub Desktop.
Save allenday/cd1b2e27417874a7407ea5caa38f7cdb to your computer and use it in GitHub Desktop.
worldpop population density per country 2020
SELECT
country_name,
COUNT(1) AS hectares,
SUM(population) AS total_pop,
SUM(population)/COUNT(1) AS pop_per_hectare
FROM
`bigquery-public-data.geo_worldpop.WorldPop_GP_100m` AS pop
,`bigquery-public-data.country_codes.country_codes` AS codes
WHERE TRUE
AND pop.country_code = codes.alpha_3_code
AND pop.population >= 0
AND pop.year = 2020
GROUP BY country_name
ORDER BY pop_per_hectare DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment