赞
踩
hive工作中用到的一些拼接函数
说明:collect_list 不去重,collect_set 去重。 column的数据类型要求是string
concat_ws和collect_set()函数实现(对某列进行去重)
concat_ws和collect_list()函数实现(对某列不进行去重)
使用函数:concat_ws(’,’,collect_set(column))
collect_set 函数,有两个作用,
第一个是去重,去除group by后的重复元素,
第二个是形成一个集合,将group by后属于同一组的集合起来成为一个集合。与contact_ws结合使用就是将这些元素以逗号分隔形成字符串。
https://www.cnblogs.com/blogyuhan/p/9274784.html
–都放在一行
SELECT person_code ,
concat_ws("\n",collect_list(
concat_ws(" ",work_date,dpt_path_name,position_name)
) ) AS work_ex
FROM dw.dw_hr_empl_work_exp_f
WHERE person_code = ‘00006’
GROUP BY person_code
–放在一列
SELECT a.person_code ,work_ex_1 FROM(
SELECT person_code ,
concat(concat_ws( ‘,’,
collect_list(
concat(
work_date,’ ‘,
dpt_path_name,’ ',
position_name
)
)
)
) AS work_ex
FROM dw.dw_hr_empl_work_exp_f
GROUP BY person_code
) a
lateral view explode(split(a.work_ex,’,’)) num as work_ex_1
WHERE a.person_code = ‘00006’
GROUP BY a.person_code,work_ex_1
–奖励情况 /
SELECT * FROM dw.dw_hr_empl_reward_punish_f
–多行变成同一行
select person_code,
concat_ws(’,’,collect_list(subject)) as order_value
from dw.dw_hr_empl_reward_punish_f
group by person_code
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。