如何从googlebigquery的子查询中访问array>struct类型的值

agxfikkp  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(420)

我有一个google大查询数据集,其中的字段位于表中的数组中。我可以使用select statemenmt中的子查询访问数组中的值。例如: (select custom_fields.value.value from tickets.custom_fields where custom_fields.value.id=35374507) AS Organization 问题是,我需要通过将表a中的一个数组中的值与表b中另一个数组中的值进行匹配来访问该数组中的值。我首先尝试在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

但这会导致以下错误:“不支持引用其他表的相关子查询,除非它们可以取消相关,例如通过将它们转换为有效的联接。”
我现在尝试在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

但这会产生以下错误:“无法访问类型为array<struct<value struct的值上的字段值< default bool,原始名称字符串,名称字符串,…>>>在[44:27]”。我想我需要取消阵列,但我不知道怎么做。如果您能帮忙,我们将不胜感激!

dfty9e19

dfty9e191#

哪个记录是嵌套的?如果两个costum字段都嵌套,则应尝试以下操作:

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

相关问题