我在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]
有什么想法可以做到吗?
答案 0 :(得分:0)
PrestoDB当前没有正式的组连接函数。但是我们可以接近:
SELECT
CompanyName,
array_join(array_agg('[' || EmployeeName || ',' || Salary || ']'), ',', '') AS EmployeeData
FROM yourTable
GROUP BY
CompanyName;