hive将两列的值拼接为一列,数字前补0

原始数据:

①使用 from_unixtime函数将日期转换为数字格式

select from_unixtime(unix_timestamp(s_birth,'yyyy-MM-dd hh:mm:ss'),'yyyyMMddhhmmss') from student_hive;

 

 

 ②使用concat函数拼接

select concat(s_id,(from_unixtime(unix_timestamp(s_birth,'yyyy-MM-dd hh:mm:ss'),'yyyyMMddhhmmss')))  from student_hive;
 

 

 

③为数字前补0

select lpad(s_id,3,0) from student_hive;
 

 

 

④ 拼接

 select concat(lpad(s_id,3,0),(from_unixtime(unix_timestamp(s_birth,'yyyy-MM-dd hh:mm:ss'),'yyyyMMddhhmmss')))  from student_hive;

 ⑤整合 

 select concat(lpad(s_id,3,0),(from_unixtime(unix_timestamp(s_birth,'yyyy-MM-dd hh:mm:ss'),'yyyyMMddhhmmss'))),s_name,s_birth,s_sex  from student_hive;

 

 

 ⑥插入新表

select concat(lpad(s_id,3,0),(from_unixtime(unix_timestamp(s_birth,'yyyy-MM-dd hh:mm:ss'),'yyyyMMddhhmmss'))),s_name,s_birth,s_sex  from student_hive;

 成功!!!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值