google-bigquery - 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
解决方案
你应该string_agg(distinct source_field)
像下面的例子那样 使用
select id, string_agg(distinct source_field) as op
from temp
group by id
推荐阅读
- postgresql - 使用表名限定时,Postgres 列引用不明确
- javascript - 获取你写的节点
- python - csv 文件显示 ... 而不是整个数据框
- java - 比较不同对象的列表并使用Stream在java8中构建新的对象列表
- java - Passing returned variables to other static methods for calculations
- javascript - 从firebase数据库表中检索列表中的数据
- html - getuikit 链接在下拉列表中不起作用
- bash - bash 脚本中的 $1 和 "$1" 有什么区别?
- objective-c - 使用 viewWithTag 的奇怪行为 UITableView
- mysql - How to get last hour data mysql?