hive中多行合并一行concat_ws(去重及不去重)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chenKFKevin/article/details/82982394

原始数据:

id  score

aaa  1

aaa  2

aaa  3

预期结果:

id  score

aaa 1,2,3

可使用

select id,concat_ws(',',collect_set(cast(colname as string))) 
    from table;

使用concat_ws函数,需将字段转成string格式,collect_set会对该列进行去重,如果不需要去重,可使用collect_list参数代替。

猜你喜欢

转载自blog.csdn.net/chenKFKevin/article/details/82982394