文章目录
居民身份证号码代表的信息:
(1)前1、2位数字表示:所在省(直辖市、自治区)的代码
(2)第3、4位数字表示:所在地级市(自治州)的代码;
(3)第5、6位数字表示:所在区(县、自治县、县级市)的代码;
(4)第7—14位数字表示:出生年、月、日; (5)第15、16位数字表示:所在地的派出所的代码;
(6)第17位数字表示性别:奇数表示男性,偶数表示女性;(7)第18位数字是校检码:也有的说是个人信息码,不是随计算机的随机产生,它是
用来检验身份证的正确性。校检码可以是0—9的数字,有时也用x表示。作为尾号的校验码,是由号码编制单位按统一的公式计算出来的,如果某人的尾号是0-9,都不会出现X,但如果尾号是10,那么就得用X来代替,因为如果用10做尾号,那么此人的身份证就变成了19位。X是罗马数字的10,用X来代替10,可以保证公民的身份证符合国家标准。
身份证号的规则不再赘述,需要注意目前一些老数据还是存在15位的身份证号,代码如下:
select id_no, id_no,
case when length(id_no) = 18 then
floor(datediff( from_unixtime(unix_timestamp(),'yyyy-MM-dd'),
concat_ws('-',substr(id_no,7,4),substr(id_no,11,2),
substr(id_no,13,2)
)
)/365 )
when length(id_no) = 15 then
floor(datediff( from_unixtime(unix_timestamp(),'yyyy-MM-dd'),
concat('19',substr(id_no,7,2),
'-', substr(id_no,9,2),
'-', substr(id_no,11,2)
)
)/365 )
else null end as age,
case when length(id_no) = 18 then
case when substr(id_no,17,1)%2 = 0 then 'F'
when substr(id_no,17,1)%2 <> 0 then 'M'
else null end
when length(id_no) = 15 then
case when substr(id_no,15)%2 = 0 then 'F'
when substr(id_no,15)%2 <> 0 then 'M'
else null end
else null end as sex
from xx
Hive中可用的内置函数
。这些函数看起来非常类似于SQL的函数,除了他们的使用有点不一样
Hive内置函数可参考以下链接:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#space-menu-link-content
https://www.cnblogs.com/MOBIN/p/5618747.html#4
https://www.yiibai.com/hive/hive_built_in_functions.html
原文:https://blog.csdn.net/u012386109/article/details/78317211