我在 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"
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
解析函数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 |
Run Code Online (Sandbox Code Playgroud)
我想要实现的是
|id|count_institution|list_institution|
|1 |2 |a,b |
|2 |2 |a,c |
|3 |1 |a |
Run Code Online (Sandbox Code Playgroud)