sql presto athena 中的分组/聚合

问题描述 投票:0回答:1

我有一张看起来像这样的桌子:

id, author
1, {entries..}
1, {entries2..}
1, {entries3..}
2, {entry x}
2, {entry y}
</snip>

我想分组并生成另一个表格,如下所示:

id, author
1, [{entries..},{entries2..},{entries3..}]
2, [{entry x},{entry y}]
</snip>

即我想按 ID 分组并将所有结果存储在 athena/presto 中的数组表中。

sql amazon-athena presto trino
1个回答
0
投票

您可以使用聚合函数

array_agg()
来返回从特定列创建的数组:

SELECT id,array_agg(author) as authors
FROM yourtable
GROUP BY id
© www.soinside.com 2019 - 2024. All rights reserved.