【问题标题】:sql query for creating map of array in aws athena (presto)用于在 aws athena (presto) 中创建数组映射的 sql 查询
【发布时间】:2019-02-01 18:39:26
【问题描述】:

我在 aws athena 中有一个包含以下列的表格

Company name  Employee Name   Salary
------------------------------------
 Apple       | John         | 50
 Apple       | Dima         | 100
 Microsoft   | Bart         | 75
 Google      | Harry        | 90
 Google      | Noah         | 80

我想通过单个查询生成下表,最好使用数组映射

Company name  Employee Data
------------------------------------
 Apple       | [John,50],[Dima,100]
 Microsoft   | [Bart,75]
 Google      | [Harry,90],[Noah,80]

你知道怎么做吗?

【问题讨论】:

  • 是否有listagg 函数或类似的东西?
  • 我已经用arrayagg解决了,但我担心值的顺序可能不一样,例如:select company_name, array_join(array_agg(salary),','), array_join (array_agg(employee_name),',') from db.stats group by company_name;

标签: sql amazon-athena presto aws-glue


【解决方案1】:

PrestoDB 目前没有正式的组连接函数。但我们可以接近:

SELECT
    CompanyName,
    array_join(array_agg('[' || EmployeeName || ',' || Salary || ']'), ',', '') AS EmployeeData
FROM yourTable
GROUP BY
    CompanyName;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-17
    • 1970-01-01
    • 2020-06-10
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 2020-07-06
    相关资源
    最近更新 更多