hive 实现将多行记录合并成一行:concat_ws,collect_set,collect_list

数据表的记录如下

5112 960024
5112 960025
5112 960026
5112 960027
5112 960028
5113 960043
5113 960044
5113 960045
5113 960046

select product_id, concat_ws('_',collect_set(promotion_id)) as promotion_ids from product_promotion group by product_id

执行结果:

  1. 5112 960024_960025_960026_960027_960028

  2. 5113 960043_960044_960045_960046

  3. Time taken: 3.116 seconds

 

collect_list:  合成数值, 但是有重复

collect_set: 合成数组,但是已去重

    原文作者:我家小宝_朱朱
    原文地址: https://blog.csdn.net/zhuchunyan_aijia/article/details/117300632
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞