Google bigquery 连接来自同一表的BigQuery中具有相同id的行

Google bigquery 连接来自同一表的BigQuery中具有相同id的行,google-bigquery,Google Bigquery,我正在google bigquery中运行此查询 SELECT rep.key.id as id, te.cmnt as comment FROM `table` rep, UNNEST(tre) as te WHERE u_id LIKE 'test' ORDER BY cts DESC 而我得到了这个 Id comment --------------------------------- 5165356444286976 HEloo 516

我正在google bigquery中运行此查询

SELECT rep.key.id as id, te.cmnt as comment
FROM `table` rep, UNNEST(tre) as te
WHERE u_id LIKE 'test'
ORDER BY cts DESC
而我得到了这个

Id                    comment
---------------------------------
5165356444286976      HEloo
5165356444286976      TEST
5165356444286976
我希望合并具有相同id的所有注释,例如如下所示:

Id                    comment
---------------------------------
5165356444286976      HEloo, TEST
使用
字符串\u AGG()

WITH table AS (
  SELECT 'test' u_id, STRUCT(1 AS id) AS key, [STRUCT('hey' AS cmnt)] AS tre, 3 cts
  UNION ALL 
  SELECT 'test', STRUCT(1), [STRUCT('you')], 2
  UNION ALL 
  SELECT 'test', STRUCT(1), [STRUCT(CAST(null AS STRING))], 1
)


SELECT rep.key.id as id, STRING_AGG(te.cmnt, ', ' ORDER BY cts DESC) AS comments
FROM `table` rep, UNNEST(tre) as te
WHERE u_id LIKE 'test'
GROUP BY id