【问题标题】:How to concat two columns into new column in BQ Table如何将两列连接到 BQ 表中的新列
【发布时间】:2023-03-19 14:46:01
【问题描述】:

我尝试将两列记录合并为一列,但在执行此操作时遇到了问题。请帮助我更好地理解我错过了什么。

表格:

Row    add.line1          add.line2
1        name1             street1
2        name2             street2

代码:

select concat('[{'line1':'add.line1','line2':'add.line2'}]') as completeaddr from `<project_id.dataset.table>`,
UNNEST(address) as add

预期输出:

Row    add.line1          add.line2                completeaddr
1        name1             street1       [{'line1': 'name1','line2': 'street1'}]
2        name2             street2       [{'line1': 'name2','line2': 'street2'}]

【问题讨论】:

    标签: sql google-bigquery


    【解决方案1】:

    考虑以下方法

    select *, to_json_string(add) as completeaddr 
    from your_table       
    

    如果应用于您问题中的样本数据 - 输出是

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-26
      • 2018-09-04
      相关资源
      最近更新 更多