[英]Nested Fields in Google BigQuery
我正在嘗試取消嵌套一些嵌套字段並在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
您可以限定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
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.