简体   繁体   English

使用记录行作为列 BigQuery

[英]Use record rows as columns BigQuery

Suppose I have a table with rows like this table , where each row of the table has records in an array form.假设我有一个表,其中包含像这个这样的行,其中表的每一行都有数组形式的记录。

Using Bigquery, Is there a way I can turn this into a table that has 'a', 'b', 'c' as its own columns, with 100, 46, 29 as the values in the rows?使用 Bigquery,有没有一种方法可以将其转换为一个表,该表将“a”、“b”、“c”作为其自己的列,并将 100、46、29 作为行中的值?

Ie turn即转

Row | abc_keys | abc_intValues
------------------------------
1   | a        | 100
    | b        | 46
    | c        | 29
2   | a        | 101
    | b        | 47
    | c        | 30

into进入

Row | a   | b  | c
-------------------
1   | 100 | 46 | 29
2   | 101 | 47 | 30

Consider below approach考虑以下方法

select * except(row_hash) from (
  select keys, intValues, to_json_string(t) row_hash
  from your_table t, unnest(abc)
)
pivot (any_value(intValues) for keys in ('a', 'b', 'c'))    

if applied to sample data in your question - output is如果应用于您问题中的示例数据 - output 是

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM