Bigquery-重复字串

时间:2019-06-05 08:55:41

标签: google-bigquery

我使用一个字符串,现在我想使用输出,但是由于出现split-输出被认为是Repeated Sting,因此也被认为是ARRAY的错误,所以出现了错误。

我该如何解决?

谢谢

With ex1 as (
SELECT 'test1,test2' as example
),

ex2 as (
SELECT 'test1' as str1, 5 as value)

SELECT * 
from

(SELECT split(example,',') as strings
from ex1)

left join 
    ex2
on str1 = strings

2 个答案:

答案 0 :(得分:3)

在使用LEFT JOIN之前,应先UNNEST数组:

With ex1 as (
SELECT 'test1,test2' as example
),
ex2 as (
SELECT 'test1' as str1, 5 as value)
SELECT  *
from
UNNEST ((SELECT split(example,',') as strings
from ex1
)) as strings
left join 
ex2
on str1 = strings

答案 1 :(得分:3)

您需要取消分割结果:

WITH 
ex1 AS (
SELECT 'test1,test2' as example),
ex2 AS (
SELECT 'test1' as str1, 5 as value)
SELECT * from
(SELECT * FROM UNNEST((SELECT split(example) FROM ex1)) as strings)
left join 
    ex2
on str1 = strings