Skip to content

Instantly share code, notes, and snippets.

@jamiekt
Last active October 22, 2022 16:41
Show Gist options
  • Save jamiekt/67cc506bd6234f493e6d4c0ae299a399 to your computer and use it in GitHub Desktop.
Save jamiekt/67cc506bd6234f493e6d4c0ae299a399 to your computer and use it in GitHub Desktop.
ARRAY() with SELECT AS STRUCT
SELECT c.borough,c.year,
ARRAY(
select as struct c2.month,sum(value) crime_tally
from `bigquery-public-data.london_crime.crime_by_lsoa` as c2
where c.borough = c2.borough
and c.year = c2.year
group by c2.month
) as monthly_summary
FROM (
select distinct borough,year
from `bigquery-public-data.london_crime.crime_by_lsoa` c
) c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment