【问题标题】:how to count repetitive values in array GBQ?如何计算数组GBQ中的重复值?
【发布时间】:2021-10-29 16:35:17
【问题描述】:

如何计算 Google-Big-Query 中每个数组的重复值?

数据:

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

如何获得:

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

【问题讨论】:

    标签: sql arrays google-bigquery


    【解决方案1】:

    考虑以下方法

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

    有输出

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-12
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-07
      • 1970-01-01
      • 2019-07-22
      相关资源
      最近更新 更多