sql - 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
您要搜索的)
推荐阅读
- tensorflow - 为什么 K.gradients 没有返回输入的损失梯度
- docker - 我应该为 AKS 使用哪个 dotnet docker 映像?
- python - 什么是最快的算法:在字符串列表中,删除作为另一个字符串的子字符串的所有字符串 [Python(或其他语言)]
- java - 有什么方法可以使用 ViewBinding 为参数化布局充气?
- python - Python Pandas 加载日期和日期范围
- sql - 用于获取具有多个值的单个列的 SQL 查询
- javascript - 如何在 JavaScript 中与 json 交互?
- r - 如何将不同的行值组合成R中的单列
- python - VS Code 中的 Python:从子文件夹导入模块时出错
- python - 我该怎么做才能使我的约会时间变得可行?