Skip to content

Instantly share code, notes, and snippets.

@mbforr
Created July 30, 2021 02:31
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 mbforr/2a717cec73219511a89aeb0e37b384fd to your computer and use it in GitHub Desktop.
Save mbforr/2a717cec73219511a89aeb0e37b384fd to your computer and use it in GitHub Desktop.
# create an aggregated CTE first
WITH
zips_311 AS (
SELECT
incident_zip,
COUNT(unique_key) AS count
FROM
`bigquery-public-data.new_york_311.311_service_requests`
GROUP BY
incident_zip )
# join the CTE table below using zip code
SELECT
b.zip_code_geom,
a.incident_zip,
a.count
FROM
zips_311 a
JOIN
`bigquery-public-data.geo_us_boundaries.zip_codes` b
ON
a.incident_zip = b.zip_code
ORDER BY
a.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment