Hive列拼接

本文介绍了在Hive中如何使用concat_ws和collect_list进行列数据的拼接,以及如何通过full outer join实现全连接操作。示例展示了在无线优惠券数据上进行用户优惠券统计和详情拼接的过程,输出结果包含了用户ID、优惠券数量、总金额等信息。
摘要由CSDN通过智能技术生成

在工作中需要根据user_id将两列以一定规则合并,实现语句如下:

select user_id,concat_ws('@',collect_list(concat(save_on,'#',end_time)))  //效果为***#***@***#***
from default.wireless_coupons 
where partitiontime=:DAY and status=0 and end_time>concat_ws('-',substr(partitiontime,0,4),substr(partitiontime,5,2),substr(partitiontime,7,2)) and coupon_type=0
group by user_id


在hive中join默认为inner join,需要full outer join实现全连接,实例:

INSERT OVERWRITE TABLE userportrait.user_f_portrait_coupons_d PARTITION(PARTITIONTIME=:DAY)
select (case when man.user_id is NULL then zhi.user_id else man.user_id end) as user_id,
((case when man_count is NULL then 0 else man_count end) + (case when zhi_count is NULL then 0 else zhi_count end)) as coupons_count,
((case when zhi_sum is NULL then 0 else zhi_sum end) + (case when man_sum is NUL

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值