Created
July 31, 2021 03:21
-
-
Save mbforr/57aba8aec5fa58053b5eec2b2d6b5613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH | |
counties AS ( | |
SELECT | |
a.total_pop, | |
b.* | |
FROM | |
`bigquery-public-data.census_bureau_acs.county_2018_1yr` a | |
JOIN | |
`bigquery-public-data.geo_us_boundaries.counties` b | |
USING | |
(geo_id) ) | |
SELECT | |
state_fips_code, | |
# here we use the CASE expression to say when the total_pop is over 500k, then include the value, otherwise count it as null | |
# more here: https://cloud.google.com/bigquery/docs/reference/standard-sql/conditional_expressions#case | |
AVG(CASE | |
WHEN total_pop > 500000 THEN total_pop | |
ELSE | |
NULL | |
END | |
) | |
FROM | |
counties | |
GROUP BY | |
state_fips_code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment