mysql根据身份证提取生日和性别

update security_user set sex='女' where id in (  select a.id from (  SELECT id , SUBSTR(ID_CARD,7,8),SUBSTR(ID_CARD,17,1),ID_CARD,birthday,sex from security_user   where LENGTH(ID_CARD) =18   and sex is null    and data_state=1 and (SUBSTR(ID_CARD,17,1))%2=0) a  );
SUBSTR(ID_CARD,17,1) 截取出判断性别的数字 
mysql根据身份证提取生日和性别_第1张图片
update security_user set sex='男' where id in (  select a.id from (  SELECT id , SUBSTR(ID_CARD,7,8),SUBSTR(ID_CARD,17,1),ID_CARD,birthday,sex from security_user   where LENGTH(ID_CARD) =18   and sex is null    and data_state=1 and (SUBSTR(ID_CARD,17,1))%2 !=0) a  );

mysql根据身份证提取生日和性别_第2张图片










update security_user  set birthday=SUBSTR(ID_CARD,7,8)   where LENGTH(ID_CARD) =18   and birthday is null ;

update  security_user set birthday=  CONCAT(left(birthday,4),'-',right(birthday,LENGTH(birthday)-4))  where LENGTH(birthday)=8 ;
update  security_user set birthday=  CONCAT(left(birthday,7),'-',right(birthday,LENGTH(birthday)-7))  where LENGTH(birthday)=9 ;

你可能感兴趣的:(数据库)