假设我有一张这样的 table ,
表:qa_list
id | question_id | question | answer |
---------+--------------+------------+-------------
1 | 100 | question1 | answer |
2 | 101 | question2 | answer |
3 | 102 | question3 | answer |
4 | ...
... | ...
以及一个给出以下结果的查询(因为我找不到转置表格的直接方法),
表:qa_map
id | qa_map
--------+---------
1 | {question1=answer,question2=answer,question3=answer, ....}
其中 qa_map 是任意数量的问题和答案的 map_agg 的结果。
有没有办法将 qa_map 取消嵌套到任意数量的列,如下所示?
id | Question_1 | Answer_1 | Question_2 | Answer_2 | Question_3 | ....
---------+-------------+-----------+-------------+-----------+-------------+
1 | question | answer | question | answer | question | ....
AWS Athena/Presto-0.172
最佳答案
不,无法编写根据数据产生不同列数的查询。在查询执行开始之前必须知道这些列。您拥有的 map 与您将要到达的 map 一样接近。
如果您说明想要这样做的动机,我们可能会通过其他方式帮助您实现最终目标。
关于presto - Athena/Presto - UNNEST 映射到列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62876977/