【发布时间】:2020-12-20 11:37:58
【问题描述】:
我正在尝试创建一个视图,其中包括取消嵌套 BigQuery 中名为客户的表中的一些值。 JSON 格式的客户表的一行示例如下所示:
{
"customer_id": "12345",
"created_date": "2020-12-20",
"customer_purchases": [
{
"created_date": "2020-12-20",
"item_id": 100
}
]
}
我希望每一行都是客户购买的视图,其列与客户表中的列完全相同。因此,我将客户购买的内容取消嵌套,如下所示:
SELECT
*
FROM `sales.customers`,
UNNEST (customer_purchases)
但是我现在收到一个错误:
Duplicate column name 'created_date' in definition of view 'sales.customers_purchases_view'
我可以创建一个怪物查询,在其中重命名所有重复的字段,但这并不理想,并且难以持续进行。无论如何,视图是否可以为任何未嵌套的列添加前缀或其他内容?
【问题讨论】:
-
请提供输入数据样本和相应的预期输出 - 请参阅How to create a Minimal, Reproducible Example
标签: sql google-bigquery unnest