gpt4 book ai didi

google-bigquery - 大查询 : How to extract only certain field from REPEATED records as another REPEATED field

转载 作者:行者123 更新时间:2023-12-05 03:04:07 25 4
gpt4 key购买 nike

这是 BigQuery 中的示例表:

WITH test AS (
SELECT
[
STRUCT("Rudisha" as name, 123 as id),
STRUCT("Murphy" as name, 124 as id),
STRUCT("Bosse" as name, 125 as id),
STRUCT("Rotich" as name, 126 as id)
] AS data

UNION

[
STRUCT("Lewandowski" as name, 127 as id),
STRUCT("Kipketer" as name, 128 as id),
STRUCT("Berian" as name, 129 as id)
] AS data
)

这里我想提取记录字段(“数据”)中的“id”字段作为可重复字段。所以行数将保持不变,但只有重复类型的 ids 字段:

ids: [123, 124, 125, 126]
ids: [127, 128, 129]

我该怎么做?

最佳答案

以下是 BigQuery 标准 SQL

#standardSQL
WITH test AS (
SELECT
[
STRUCT("Rudisha" AS name, 123 AS id),
STRUCT("Murphy" AS name, 124 AS id),
STRUCT("Bosse" AS name, 125 AS id),
STRUCT("Rotich" AS name, 126 AS id)
] AS data
UNION ALL SELECT
[
STRUCT("Lewandowski" AS name, 127 AS id),
STRUCT("Kipketer" AS name, 128 AS id),
STRUCT("Berian" AS name, 129 AS id)
] AS data
)
SELECT ARRAY(SELECT id FROM UNNEST(data)) ids
FROM test

关于google-bigquery - 大查询 : How to extract only certain field from REPEATED records as another REPEATED field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53146197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com