【问题标题】:How to pivot on a column in BigQuery without knowing values beforehand? [duplicate]如何在事先不知道值的情况下对 BigQuery 中的列进行旋转? [复制]
【发布时间】:2018-11-16 18:17:07
【问题描述】:

我有一张桌子,看起来像:

| id|cat|elems |
|---|---|------|
| 1 | A |[a, b]|
| 1 | B |[b, c]|
| 2 | C |[b, c]|

elems 是一个数组列。

有没有一种方法可以在不硬编码cat 的值的情况下在cat 列上进行旋转(所以不在cat='A' 上执行CASE/IF 等)? 期望的结果如下所示:

| id| A    | B    |   C  |
|---|------|------|------|
| 1 |[a, b]|[b, c]| NULL |
| 2 | NULL | NULL |[b, c]|

【问题讨论】:

    标签: google-bigquery pivot pivot-table


    【解决方案1】:

    Google BigQuery 没有PIVOT 函数。您可以在文档here 中查看如何模拟旋转。

    另外我建议你看看这两个 Stack Overflow 问题:

    1. How to Pivot in Google BigQuery
    2. Transpose rows into columns in BigQuery (Pivot implementation)

    【讨论】:

    • 似乎没有办法对案例进行硬编码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-21
    • 1970-01-01
    • 2018-08-20
    • 2020-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多