6

我想使用 LISTAGG 在 Amazon Athena 中进行查询。有什么方法可以将数据聚合到列表或字符串中?

作为Amazon Athena 用户指南

grouping_expressions 元素可以是任何函数(如 SUM、AVG、COUNT 等)

4

1 回答 1

17

选项1:数组

with t(i) as (select 1 union all select 2 union all select 3) 
select  array_agg(i) as result 
from    t
;

  result
-----------
 [3, 2, 1]

选项 2:字符串

with t(i) as (select 1 union all select 2 union all select 3) 
select  array_join(array_agg(i),',') as result 
from    t
;

 result
--------
 1,3,2
于 2017-03-19T18:45:37.170 回答