简体   繁体   中英

Bigquery Split with comma in data

Below is my source table, need expected result but getting incorrect result for the below query. Please help

在此处输入图像描述

Query:

select ID, metric, value from ( SELECT *, REGEXP_REPLACE(SPLIT(pair, ':')[OFFSET(0)], r'^"|"$', '') metric, REGEXP_REPLACE(SPLIT(pair, ':')[OFFSET(1)], r'^"|"$', '') value FROM, UNNEST(SPLIT(REGEXP_REPLACE(to_json_string(), r'{|}', ''))) pair ) where metric not in (ID) order by metric, value;

Expected result:

ID度量值100位 890908,890909,890910, 890911

incorrect result with above query:

在此处输入图像描述

as far as I can see there is no need to touch the Value column as you only add a column named "metric"

I would suggest working with an Case statement

The source is having dynamic columns. Hence, we can't hard code any columns except ID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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