【问题标题】:LEFT JOIN WITH UNNEST ON BIGQUERY在 BIGQUERY 上使用 UNNEST 左连接
【发布时间】:2020-05-22 09:18:46
【问题描述】:

我有一个 bigquery 表,我想将它与公共数据集 bigquery-public-data.crypto_bitcoin.transactions 进行外部联接。由于事务表有两个嵌套字段输入和输出。 join 的结果也有嵌套值。我想删除那些。

SELECT *
FROM `asymmetric-glow-274808.mydataset.txid` as mytable
LEFT JOIN `bigquery-public-data.crypto_bitcoin.transactions` as datasource
ON mytable.string_field_3 = datasource.hash
LIMIT 1

例子

mytable
txid
1

transactions
hash    inputs.index  inputs.type outputs.index outputs.type
1       0              aaa            0          aaa
        1              bbb            1          bbb

After join im getting
txid hash    inputs.index  inputs.type outputs.index outputs.type
1      1           0              aaa            0          aaa
                   1              bbb            1          bbb

what i want
txid hash    inputs.index  inputs.type outputs.index outputs.type
1      1           0              aaa            0          aaa
1      1           1              bbb            1          bbb

怎么做?

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

    看来你需要类似的东西

    SELECT
      *
    FROM
      mytable
    LEFT JOIN (
      SELECT
        datasource.hash, inputs, outputs
      FROM
        `bigquery-public-data.crypto_bitcoin.transactions` AS datasource,
        datasource.inputs inputs,
        datasource.outputs outputs) d
    ON
      mytable.string_field_3 = d.hash
    LIMIT
      100
    

    【讨论】:

    • 如果答案有用,请考虑对其进行投票。您可以点击 ▲ 对其进行投票
    猜你喜欢
    • 2017-11-06
    • 2019-12-27
    • 1970-01-01
    • 1970-01-01
    • 2018-09-16
    • 2021-01-01
    • 2020-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多