concat_ws和collect_set一般搭配使用
官方释义
collect_set
collect_set(expr) - Collects and returns a set of unique elements.
concat_ws
concat_ws(sep, [str | array(str)]+) - Returns the concatenation of the strings separated by sep.
1.concat_ws: 用指定的字符连接字符串
连接字符串:
concat_ws("", a, b),输出结果将会是:“a_b”。
数组元素连接:
concat_ws("", [a,b,c]),输出结果将会是:“a_b_c”。
2.collect_set: 把聚合的数据组合成一个数组,一般搭配group by 使用。
select a.id,concat_ws(',',collect_set(a.MIXMAJORKEY)) as ORGINALMAJORKEY from (select id,concat(name,'_',age,'_',gender) as MIXMAJORKEY from dc_sma.zyftest) a group by a.id
结果显示