我正在尝试取消嵌套一些嵌套字段,并在Google BigQuery中进行子查询。
这很好。
SELECT id,
custom_field_options
FROM `project.database.ticket_fields`
'custom_field_options'是一个嵌套字段,这给我带来了一些问题。我有“ custom_field_options.id”和“ custom_field_options.name”以及另外两个嵌套字段。
这也很好。
SELECT ticket_fields.id,
ticket_fields.raw_title,
ticket_custom_fields.name AS ticket_custom_fields_name,
ticket_custom_fields.raw_name AS ticket_custom_fields_raw_name,
ticket_custom_fields.value AS ticket_custom_fields_value,
ticket_fields.created_at
FROM `project.database.ticket_fields` AS ticket_fields
LEFT JOIN UNNEST(custom_field_options) AS ticket_custom_fields
GROUP BY 1,2,3,4,5,6
分别运行时,这两个查询都可以正常运行。现在,我试图将第一个查询作为第二个查询的子查询运行,以从该查询中拉回所有ID,然后在此基础上运行下面的查询。
SELECT ticket_fields.id,
ticket_fields.raw_title,
ticket_custom_fields.name AS ticket_custom_fields_name,
ticket_custom_fields.raw_name AS ticket_custom_fields_raw_name,
ticket_custom_fields.value AS ticket_custom_fields_value,
ticket_fields.created_at
FROM `project.database.ticket_fields` AS ticket_fields
LEFT JOIN UNNEST(custom_field_options) AS ticket_custom_fields
WHERE id IN (SELECT id,
custom_field_options
FROM `project.database.ticket_fields`)
GROUP BY 1,2,3,4,5,6
答案 0 :(得分:3)
您可以使id
列名合格,以使引用明确:
SELECT ticket_fields.id,
ticket_fields.raw_title,
ticket_custom_fields.name AS ticket_custom_fields_name,
ticket_custom_fields.raw_name AS ticket_custom_fields_raw_name,
ticket_custom_fields.value AS ticket_custom_fields_value,
ticket_fields.created_at
FROM `project.database.ticket_fields` AS ticket_fields
LEFT JOIN UNNEST(custom_field_options) AS ticket_custom_fields
WHERE ticket_fields.id IN (SELECT id,
custom_field_options
FROM `project.database.ticket_fields`)
GROUP BY 1,2,3,4,5,6
(我假设ticket_fields.id
是您要搜索的id
)