Skip to content

Instantly share code, notes, and snippets.

@lfy79001
Created April 30, 2024 16:47
Show Gist options
  • Save lfy79001/91350ad2fe4cc9de909ac004de04dbe3 to your computer and use it in GitHub Desktop.
Save lfy79001/91350ad2fe4cc9de909ac004de04dbe3 to your computer and use it in GitHub Desktop.
SELECT
age.country_name,
SUM(age.population) AS under_25,
pop.midyear_population AS total,
ROUND((SUM(age.population) / pop.midyear_population) * 100,2) AS pct_under_25
FROM (
SELECT country_name, population, country_code
FROM `bigquery-public-data.census_bureau_international.midyear_population_agespecific`
WHERE year =2017 AND age < 25) age
INNER JOIN (
SELECT midyear_population, country_code
FROM `bigquery-public-data.census_bureau_international.midyear_population`
WHERE year = 2017) pop
ON age.country_code = pop.country_code
GROUP BY 1,3
ORDER BY 4 DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment