首页 > 解决方案 > BigQuery for Standard SQL 中的收集集等效项是什么

问题描述

我有下表,其中我试图找到一个array set给定的id. 我知道collect_set在 Hive 中可用,但我想知道它在 BigQuery 中的等价物。我正在使用Standard SQL.

这是我的查询

with temp as (
select "1" as id, "a" as source_field
union all
select "1" as id, "b" as source_field
union all 
select "1" as id, "b" as source_field
)
select id, string_agg(source_field) as op
from temp
group by id 

这返回

id   op
1   a,b,b

而我需要

id   op
1   a,b

因为我只想要给定的不同成员id

标签: google-bigquery

解决方案


你应该string_agg(distinct source_field)像下面的例子那样 使用

select id, string_agg(distinct source_field) as op
from temp
group by id 

推荐阅读