Hive 根据身份证提取年龄、生日、性别

select 
identity_card
,if(LENGTH(identity_card)=18, cast(YEAR(current_timestamp())-CAST(SUBSTR(identity_card,7,4) as int) as int), 0) '年龄'
,case 
when length(identity_card) = 18 then concat_ws('-','2018',substr(identity_card,11,2),substr(identity_card,13,2))
when length(identity_card) = 15 then concat('19',substr(identity_card,7,2),'-', substr(identity_card,9,2),'-', substr(identity_card,11,2))
else 'Other' end '生日'
,case 
when length(identity_card) = 18 then if(substr(identity_card,17,1)%2 = 0,'F','M')
when length(identity_card) = 15 then if(substr(identity_card,15)%2 = 0,'F','M')
else 'Other' end '性别'
from yc_ods.ods_driver
where length(identity_card) = 15

 

posted @ 2018-12-21 18:29  chengdex  阅读(5241)  评论(0)    收藏  举报