在 BigQuery 中将用逗号分隔值的列分隔成多行

问题描述 投票:0回答:1

我的数据仓库中有这张表

身份证号码 类型 姓名
1 水果 香蕉、苹果、浆果
2 蔬菜 胡萝卜、番茄

我希望它查询如下:

身份证号码 类型 姓名
1 水果 香蕉
1 水果 苹果
1 水果 浆果
2 蔬菜 胡萝卜
2 蔬菜 番茄

我尝试使用 split finction 但它不起作用,我发现人们提到了 unnest 但这个功能在 bigquery 中不可用

google-bigquery
1个回答
0
投票

这是完整的解决方案:

create table `test.produce`
as 
select 1 as id, "fruit" as type, ["banana", "apple", "berry"] as name
union all
select 2, "vegetable", ["carrot", "tomato"];

select L.* except(name), name from `test.produce` as L left join unnest(name) as name

BigQuery 仅支持取消嵌套fine

© www.soinside.com 2019 - 2024. All rights reserved.