【发布时间】:2020-07-14 18:25:23
【问题描述】:
我对 Bigquery 中的 STRING_AGG 有疑问。 我正在尝试:
SELECT
id,
institution,
COUNT(DISTINCT institution) OVER (PARTITION BY id) as count_intitution
STRING_AGG(DISTINCT institution,"," ) OVER (PARTITION BY id) as list_intitution
FROM
name_table
WHERE
DATE(created_at) = "2020-02-02"
我得到这个错误:
解析函数 string_agg 不支持 DISTINCT。
BQ 文档说它允许使用“DISTINCT”
https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#string_agg
但显然它不支持“partition by”,为什么?
编辑:
当前表是这样的(是一个例子,表的属性比较多)
|id |institution|
|1 | a |
|1 | b |
|2 | a |
|2 | c |
|3 | a |
|1 | a |
而我想要达到的是
|id|count_institution|list_institution|
|1 |2 |a,b |
|2 |2 |a,c |
|3 |1 |a |
【问题讨论】:
-
But apparently it doesn't support "partition by", why?最好向谷歌提出这个问题。
标签: sql google-bigquery