简体   繁体   English

我如何将字符串字段取消嵌套到 SQL BIGQUERY 中的行中

[英]How can i unnest a string field into rows in SQL BIGQUERY

how to unnest a string field Table Flags: id of type integer and categories of type string如何取消嵌套字符串字段表标志:类型为 integer 的 ID 和类型为字符串的类别

ID ID Categories类别
1201 1201 Uncategorized, Issues from Project Side, CI Configurations Issue未分类,项目方问题,CI 配置问题
1202 1202 Machine Stability, Machine Stability, Machine Stability,机器稳定性,机器稳定性,机器稳定性,

Output needed需要Output

ID ID categories类别
1201 1201 Uncategorized未分类
1201 1201 Issues from project side项目方的问题
1201 1201 CI Configurations Issue CI 配置问题
1202 1202 Machine Stability机器稳定性
1202 1202 Machine Stability机器稳定性
1202 1202 Machine Stability机器稳定性

Thanks谢谢

 select *,
  (select ( categories)
    from unnest(split(categories)) categories
 )as  distinct_product_count
   

 FROM `Flags` 

i got error Scalar subquery produced more than one element我得到错误标量子查询产生了不止一个元素

You don't need to use a subquery to do this, you are right to use split within the unnest function but you can specify it right after the from clause like this:您不需要使用子查询来执行此操作,您可以在unnest function 中使用split ,但您可以在from子句之后立即指定它,如下所示:

select 
  ID,
  category
from `Flags`, unnest(split(categories)) as category

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM