Skip to content
Advertisement

BigQuery count each item in array across table

I cannot quite find what I’m looking for, so here goes:

I’m looking for a way to get a count of the number of times an item occurs in an array across the entire table.

Imagine you have a table child_names with two columns – user_id and children

  • I know it’s unusual to have two children with same name, but bear with me

.

I am looking for a result that would have two columns

So far I have this

But this gives me a count of how many children have that name per parent, not per table.

I get

I hope that makes sense. Any help would be appreciated.

Advertisement

Answer

Use below

if applied to sample data in your question – output is

enter image description here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement