hive 多行合并

it2023-05-07  72

collect_set&collect_list

1,、concat_ws和collect_set()函数实现(对某列进行去重)

2、concat_ws和collect_list()函数实现(对某列进行不去重)

 

CONCAT_WS()

CONCAT_WS(separator, str1, str2,...)

第一个参数剩余参数间的分隔符。分隔符可以是与剩余参数一样的字符串。如果分隔符是 NULL,返回值也将为 NULL。这个函数会跳过分隔符参数后的任何 NULL 和空字符串。分隔符将被加到被连接的字符串之间

concat_ws() 可与group by搭配使用

例如:

select id ,concat_ws(',',collect_set(cast(num as string))) from from table group by id;

group_concat

用法:

select A,GROUP_CONCAT(B) from table group by A ;

如不支持group_concat,使用concat_ws,collect_list替换

select id ,concat_ws(',',collect_list(cast(num as string))) from from table group by id;

 

最新回复(0)