[英]creating nested array presto
但我有這張表:
with cte (customer_id, product, sell) as (
values
(1, 'a', 100),
(1, 'b', 150),
(2, 'a', 90),
(2, 'b', 110)
)
select * from cte
我想要如下結果:
+----------------------------------------------------------+
| result |
+----------------------------------------------------------+
| {1: {"a": 100, "b": 150}, 2: {"a":90, "b": 110}} |
+----------------------------------------------------------+
您的結果不是嵌套數組,而是嵌套映射。 我會說,除非這是一些更大查詢的一部分,否則嘗試將整個表映射到單行是很奇怪的,尤其是考慮到通常由 Athena 處理的數據大小,但對於此測試數據,您可以使用map_agg
和嵌套分組:
with cte (customer_id, product, sell) as (
values (1, 'a', 100),
(1, 'b', 150),
(2, 'a', 90),
(2, 'b', 110)
)
select map_agg(customer_id, m) as result
from (
select customer_id, map_agg(product, sell) m
from cte
group by customer_id
)
group by true -- fake grouping
輸出:
結果 |
---|
{1={a=100, b=150}, 2={a=90, b=110}} |
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.