在 aws athena 中按列列出汇总结果?

List aggregated result over group by column in aws athena?

我有一个 table 具有以下架构

Test Name, Marks

一些条目是:(maths,78),(maths,90),(English,20),(English,40)

现在我希望在 'Test Name' 上将此 table 分组,这样输出=

maths [78,90], English [20,40]

在 AWS 雅典娜中。我真的看不到任何聚合函数在互联网上的 'group by' 子句上执行此操作

您可以使用array_agg函数:

WITH example_table AS
 (SELECT 'Maths' as test_name, 78 as marks UNION ALL
  SELECT 'Maths', 90 UNION ALL
  SELECT 'English', 20 UNION ALL
  SELECT 'English', 40)
SELECT test_name, array_agg(marks) as marks
FROM example_table
GROUP BY test_name

如果您需要对这些值进行更花哨的操作,您可以添加 reduce 函数:

WITH example_table AS
 (SELECT 'maths' as test_name, 78 as marks UNION ALL
  SELECT 'maths', 90 UNION ALL
  SELECT 'English', 20 UNION ALL
  SELECT 'English', 40)
SELECT test_name, reduce(array_agg(marks), ARRAY[], (s, x) -> s || x, s -> s) as marks
FROM example_table
GROUP BY test_name

您在寻找 array_agg() 吗?

select test_name, array_agg(marks)
from t
group by test_name;