如何在AWS Athena中使用LISTAGG?

时间:2017-01-24 06:31:43

标签: amazon-web-services amazon-athena

我想使用LISTAGG在Amazon Athena中查询。 有没有办法将数据聚合成列表或字符串?

作为Amazon Athena User Guide

  

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

1 个答案:

答案 0 :(得分:4)

选项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