mysql根据身份证查询年龄,地址,性别
2016-05-25 17:54
573 查看
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`
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`
相关文章推荐
- mysql 5.7 密码变更变化(1)
- mysql 双实例配置
- 新浪爱彩票DBA总监:为什么你的MySQL跑得很慢?
- MySQL索引和查询优化
- MYSQL连接池应用场景
- mysql查看数据库命令
- MySQL索引设计一些策略
- MySql增删改查
- 连接本地MySQL被拒绝连接如何处理
- MYSQL数据库学习笔记0523
- MYSQL系列-Mysql存储引擎选择
- mysql远程链接失败
- mysql集群配置
- MySQL 简单语句(2)
- MYSQL知识点整理
- 开发中遇到的l异常(mysql为主)
- 利用DBExportDoc V1.0 For MySQL自动生成数据库表结构文档
- MySql 5.7:忘记root密码的登录方法
- Mysqldump 参数详解(全)
- 利用mysql的c api,在vs2010中操作mysql