根据18位身份证和15位身份证输出省份性别和年龄
select case left(idcard,2)
when '11' then '北京市'
when '12' then '天津市'
when '13' then '河北省'
when '14' then '山西省'
when '15' then '内蒙古自治区'
when '21' then '辽宁省'
when '22' then '吉林省'
when '23' then '黑龙江省'
when '31' then '上海市'
when '32' then '江苏省'
when '33' then '浙江省'
when '34' then '安徽省'
when '35' then '福建省'
when '36' then '江西省'
when '37' then '山东省'
when '41' then '河南省'
when '42' then '湖北省'
when '43' then '湖南省'
when '44' then '广东省'
when '45' then '广西壮族自治区'
when '46' then '海南省'
when '50' then '重庆市'
when '51' then '四川省'
when '52' then '贵州省'
when '53' then '云南省'
when '54' then '西藏自治区'
when '61' then '陕西省'
when '62' then '甘肃省'
when '63' then '青海省'
when '64' then '宁夏回族自治区'
when '65' then '新疆维吾尔自治区'
when '71' then '台湾省'
when '81' then '香港特别行政区'
when '82' then '澳门特别行政区'
else '未知'
end as 省份 ,
year(curdate())-if(length(idcard)=18,substring(idcard,7,4),if(length(idcard)=15,concat('19',substring(idcard,7,2)),null)) as 年龄,
case if(length(idcard)=18, cast(substring(idcard,17,1) as UNSIGNED)%2, if(length(idcard)=15,cast(substring(idcard,15,1) as UNSIGNED)%2,3))
when 1 then '男'
when 0 then '女'
else '未知'
end as 性别
FROM `user`
想根据18位身份证和15位身份证查询身份、年龄、性别,看网上写的这个,发现只能输出最后一行,其余的年龄输出为Null,性别输出为Null,省份能够完全输出,还有2002年出生的,年龄怎么输出。求解决办法。测试数据
421224198508136425
429006199207163644
429006199608123652
429006199808163664
429006199608163694
429006960816369
429006200208163695
429006020816369
when '11' then '北京市'
when '12' then '天津市'
when '13' then '河北省'
when '14' then '山西省'
when '15' then '内蒙古自治区'
when '21' then '辽宁省'
when '22' then '吉林省'
when '23' then '黑龙江省'
when '31' then '上海市'
when '32' then '江苏省'
when '33' then '浙江省'
when '34' then '安徽省'
when '35' then '福建省'
when '36' then '江西省'
when '37' then '山东省'
when '41' then '河南省'
when '42' then '湖北省'
when '43' then '湖南省'
when '44' then '广东省'
when '45' then '广西壮族自治区'
when '46' then '海南省'
when '50' then '重庆市'
when '51' then '四川省'
when '52' then '贵州省'
when '53' then '云南省'
when '54' then '西藏自治区'
when '61' then '陕西省'
when '62' then '甘肃省'
when '63' then '青海省'
when '64' then '宁夏回族自治区'
when '65' then '新疆维吾尔自治区'
when '71' then '台湾省'
when '81' then '香港特别行政区'
when '82' then '澳门特别行政区'
else '未知'
end as 省份 ,
year(curdate())-if(length(idcard)=18,substring(idcard,7,4),if(length(idcard)=15,concat('19',substring(idcard,7,2)),null)) as 年龄,
case if(length(idcard)=18, cast(substring(idcard,17,1) as UNSIGNED)%2, if(length(idcard)=15,cast(substring(idcard,15,1) as UNSIGNED)%2,3))
when 1 then '男'
when 0 then '女'
else '未知'
end as 性别
FROM `user`
想根据18位身份证和15位身份证查询身份、年龄、性别,看网上写的这个,发现只能输出最后一行,其余的年龄输出为Null,性别输出为Null,省份能够完全输出,还有2002年出生的,年龄怎么输出。求解决办法。测试数据
421224198508136425
429006199207163644
429006199608123652
429006199808163664
429006199608163694
429006960816369
429006200208163695
429006020816369
...全文
相关推荐
根据身份证号获取出生日期以及年龄和性别
根据手动输入的身份证号(包含15位和18位),自动计算出出生日期和性别以及年龄,不用手动再去输入,
c#根据身份证计算性别 年龄
根据给定的信息,我们可以深入探讨如何使用C#语言来解析身份证号码并从中提取性别与年龄信息。身份证号码在中国通常有两种格式:15位和18位。
根据身份证号码获取生日年龄性别
### 获取生日、年龄与性别#### 步骤一:验证身份证号码长度首先检查身份证号码的有效性,即长度是否为15位或18位。15位身份证号码在早期使用,其结构略有不同,而18位是当前的标准格式。
JAVA版身份证获取性别、出生日期及年龄
首先,中国的身份证号码由18位数字组成,其中包含了丰富的个人信息。前6位代表地区代码,第7位到第14位是出生日期(格式为YYYYMMDD),第15位至第17位为顺序号,奇数分配给男性,偶数分配给女性。
输入身份证输出生日,性别
从键盘输入一个18位或15位的身份证号码,显示器上输出年龄、性别、


应用实例
