Daniele B
Daniele B

Reputation: 20442

BigQuery: how to count specific values in a REPEATED field?

I have a STRING REPEATED field in a BigQuery table.

this is a list of rows for such field:

How can I count the total number of occurrencies of all single values?

I tried with "GROUP BY", but it seems that it's not possible to GROUP BY a REPEATED field

Upvotes: 1

Views: 2018

Answers (1)

Elliott Brossard
Elliott Brossard

Reputation: 33765

You want to UNNEST and then count:

SELECT x, COUNT(*) AS c
FROM T, UNNEST(array_column) AS x
GROUP BY x

Upvotes: 5

Related Questions