collect_list返回数组,而不是字符串。
可以使用concat_ws将数组转换为分隔符字符串。
这将起作用,评论没有特定的顺序。
select id
,concat_ws('~',collect_list(comment)) as comments
from mytable
group by id
;
+----+-------------+
| id | comments |
+----+-------------+
| 1 | ABC~PRQ~XYZ |
| 2 | LMN~OPQ |
+----+-------------+
concat() over partition by()
子句来获得相同的结果吗? - Regressor