amazon-web-services - 如何在AWS Athena中使用LISTAGG?

标签 amazon-web-services amazon-athena

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

作为Amazon Athena User Guide

The grouping_expressions element can be any function (such as SUM, AVG, COUNT, etc.)

最佳答案

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

关于amazon-web-services - 如何在AWS Athena中使用LISTAGG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41821474/

相关文章:

amazon-web-services - 如何使用cloudformation创建IAM用户/角色

amazon-web-services - Amazon m1.small 与微型实例 CPU 性能对比

node.js - 如何在 Amazon Linux EC2 上安装和设置 Node.js 、 NPM

amazon-web-services - AWS Athena 和 date_format

arrays - 查询 JSON key :Value Pairs in AWS Athena

php - 使用 php 将文件上传到 aws s3 存储桶时出现错误

amazon-web-services - SQS 队列需要什么权限才能通过 SNS 接收来自 SES 的通知?

amazon-web-services - 如何抑制 AWS Athena 查询结果中的列标题?

amazon-s3 - 使用 Glue 从 AWS RDS 到 S3 的管道

amazon-web-services - 通过 API 从 Athena Query 返回 JSON