美文网首页
sql根据省份证提取生日、性别

sql根据省份证提取生日、性别

作者: 为你变乖_09e6 | 来源:发表于2019-08-24 15:18 被阅读0次
    SELECT
        p.idcard,
        p.`gender`,
    IF (LENGTH(p.idcard) = 18,
        CAST(SUBSTRING(p.idcard, 7, 8) AS DATETIME),
        CAST(CONCAT('19',SUBSTRING(p.idcard, 7, 6)) AS DATETIME)) AS Birthday,  
    IF (SUBSTR(p.idcard, LENGTH(p.idcard) - 1,1) % 2 = 1, '男', '女') AS sex
    FROM `a_community_people_5520` p 
    WHERE
     p.idcard REGEXP '[1-8][0-8][0-9]{16}|[1-8][0-8][0-9]{15}X|[1-8][0-8][0-9]{13}'
    AND (
        LENGTH(p.idcard) = 18
        OR LENGTH(p.idcard) = 15
    )
    LIMIT 1000000
    

    相关文章

      网友评论

          本文标题:sql根据省份证提取生日、性别

          本文链接:https://www.haomeiwen.com/subject/uhkqectx.html