如何在AWS Athena中使用LISTAGG?

Shi*_*Kim 1 amazon-web-services amazon-athena

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

作为Amazon Athena用户指南

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

Dav*_*itz 6

选项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]
Run Code Online (Sandbox Code Playgroud)

选项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
Run Code Online (Sandbox Code Playgroud)