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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM