查询以返回数组中GROUP BY的所有结果

时间:2018-05-03 16:29:25

标签: sql google-bigquery

我有一个简单的BigQuery查询:

SELECT GroupingColumn, ... FROM Table GROUP BY GroupingColumn

有没有办法在嵌套数组中返回与GroupingColumn匹配的记录的所有列?

+-----------------+------------------------------------------------+
| GroupingColumn1 | ARRAY of objects containing all the columns    |
+-----------------+------------------------------------------------+
| Column1val      | [ { Column2, Column3 }, { Column2, Column3 } ] |
| Column1val      | ...                                            |
+-----------------+------------------------------------------------+

1 个答案:

答案 0 :(得分:2)

您可以使用ARRAY_AGG

SELECT GroupingColumn, ARRAY_AGG(...)
FROM Table GROUP BY GroupingColumn