繁体   English   中英

从 AWS Athena 中的数组元素分组

[英]Group by from the elements of array in AWS Athena

我有一个有两列的表。 该表具有以下架构

column_name ---> type
student_id  ---> int
subjects    ---> array<string>

样本数据为:

student_id  --->  subjects
10          --->  [Math, Science]
20          --->  [Math, English]
30          --->  [English, French]

我想按个别科目分组,即我想计算所有学生所学科目的数量。 所以我的预期结果是

Math     ---> 2
Science  ---> 1
English  ---> 2
French   ---> 1

我听说过unnest an array,但无法得到这个结果。

我应该如何处理这个?

我认为你只需要unnest

select subject, count(*)
from t cross join
     unnest(subjects) as u(subject)
group by subject;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM