Home > OS >  how to count repetitive values in array GBQ?
how to count repetitive values in array GBQ?

Time:10-30

How can I count repetitive values for each array in Google-Big-Query?

DATA:

WITH temp AS (SELECT 1 id, ["a","b", "a"] name )
SELECT * FROM temp

How to get:

1 | name | count|
  |  a   |   2  |
  |  b   |   1  |

CodePudding user response:

Consider below approach

select id, array(
    select as struct name, count(1) `count`
    from t.name name
    group by name
  ) stats
from temp t             

with output

enter image description here

  • Related