使用 Bigquery 将逗号分隔的字符串拆分为行

rav*_*ven 1 google-bigquery

我正在尝试将包含以逗号分隔的字符串的列拆分为行

输入 -

在此处输入图片说明

预期输出 -

在此处输入图片说明

我尝试使用 REGEXP_EXTRACT_ALL 但无法获得上述输出

Mik*_*ant 6

下面是 BigQuery 标准 SQL

#standardSQL
SELECT * EXCEPT(c) REPLACE(c AS country)
FROM `project.dataset.table`,
UNNEST(SPLIT(country)) c   
Run Code Online (Sandbox Code Playgroud)

如果适用于您问题中的示例数据,如下例所示

#standardSQL
WITH `project.dataset.table` AS (
  SELECT 'asia' region, 'india,china,japan' country, 100 revenue, 0.3 weight UNION ALL
  SELECT 'europe', 'uk,france,germany,italy', 75, 0.25
)
SELECT * EXCEPT(c) REPLACE(c AS country)
FROM `project.dataset.table`,
UNNEST(SPLIT(country)) c   
Run Code Online (Sandbox Code Playgroud)

结果是

Row region  country revenue weight   
1   asia    india   100     0.3  
2   asia    china   100     0.3  
3   asia    japan   100     0.3  
4   europe  uk      75      0.25     
5   europe  france  75      0.25     
6   europe  germany 75      0.25     
7   europe  italy   75      0.25     
Run Code Online (Sandbox Code Playgroud)