【问题标题】:how to access values from type ARRAY>STRUCT from within a subquery in Google BigQuery如何从 Google BigQuery 的子查询中访问 ARRAY>STRUCT 类型的值
【发布时间】:2020-10-27 00:59:45
【问题描述】:

我有一个 Google Big Query 数据集,其中的字段位于表中的数组内。我可以使用 SELECT 语句中的子查询访问数组中的值。例如: (select custom_fields.value.value from tickets.custom_fields where custom_fields.value.id=35374507) AS Organization

问题是我需要通过将表 A 中的一个数组与表 B 中另一个数组中的值进行匹配来访问表 A 中的一个数组中的值。我首先尝试通过在 SELECT 语句的子查询中使用子查询来做到这一点如下:

tickets.id,
(select (select custom_field_options.value.name from ticket_fields.custom_field_options
    where custom_field_options.value.value=(select custom_fields.value.value from 
    tickets.custom_fields where custom_fields.value.id=360014264753))
    from zendesk.ticket_fields) AS Issue
from zendesk.tickets
where tickets.id=6869

但这给出了以下错误:“不支持引用其他表的相关子查询,除非它们可以去相关,例如通过将它们转换为有效的 JOIN。”

我现在正在尝试使用 FROM 子句中的子查询来创建两个临时表并将它们连接起来,如下所示:

SELECT
  I.custom_field_options.value.name AS Issue_name,
  C.custom_fields.value.value AS Issue_value
FROM
  (select custom_field_options from zendesk.ticket_fields) As I
JOIN
  (select custom_fields from zendesk.tickets) AS C
ON I.custom_field_options.value.value = C.custom_fields.value.value
WHERE C.custom_fields.value.id=360014264753

但这会产生以下错误:“无法访问类型为 ARRAYdefault BOOL, raw_name STRING, name STRING, ...>>> at [44:27] 的字段值”。我想我需要 UNNEST 数组,但我不知道该怎么做。非常感谢您的帮助!

【问题讨论】:

  • 你检查过这个堆栈thread吗?

标签: sql google-bigquery zendesk-api


【解决方案1】:

哪条记录是嵌套的? 如果两个服装字段都是嵌套的,你应该试试这个:

SELECT
  I.custom_field_options.value.name AS Issue_name,
  C.custom_fields.value.value AS Issue_value
FROM
  (select custom_field_options from zendesk.ticket_fields, unnest(custom_field_options) custom_field_options) As I
JOIN
  (select custom_fields from zendesk.tickets, unnest(custom_fields) custom_fields) AS C
ON I.custom_field_options.value.value = C.custom_fields.value.value
WHERE C.custom_fields.value.id=360014264753

【讨论】:

    猜你喜欢
    • 2020-12-09
    • 2020-09-21
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    相关资源
    最近更新 更多