sql语句——根据身份证号提取省份、出生日期、年龄、性别。
原表

sql语句:
SELECT
case left(cardid,2)
when '' then '北京市'
when '' then '天津市'
when '' then '河北省'
when '' then '山西省'
when '' then '内蒙古自治区'
when '' then '辽宁省'
when '' then '吉林省'
when '' then '黑龙江省'
when '' then '上海市'
when '' then '江苏省'
when '' then '浙江省'
when '' then '安徽省'
when '' then '福建省'
when '' then '江西省'
when '' then '山东省'
when '' then '河南省'
when '' then '湖北省'
when '' then '湖南省'
when '' then '广东省'
when '' then '广西壮族自治区'
when '' then '海南省'
when '' then '重庆市'
when '' then '四川省'
when '' then '贵州省'
when '' then '云南省'
when '' then '西藏自治区'
when '' then '陕西省'
when '' then '甘肃省'
when '' then '青海省'
when '' then '宁夏回族自治区'
when '' then '新疆维吾尔自治区'
when '' then '台湾省'
when '' then '香港特别行政区'
when '' then '澳门特别行政区'
else '未知'
end AS 地域 ,
cast(substring(cardid,7,8) as date) as 出生日期,
year(curdate())-if(length(cardid)=18,substring(cardid,7,4),if(length(cardid)=15,concat('',substring(cardid,7,2)),null)) as 年龄,
case if(length(cardid)=18, cast(substring(cardid,17,1) as UNSIGNED)%2, if(length(cardid)=15,cast(substring(cardid,15,1) as UNSIGNED)%2,3))
when 1 then '男'
when 0 then '女'
else '未知'
end AS 性别
FROM id;
返回结果:

sql语句——根据身份证号提取省份、出生日期、年龄、性别。的更多相关文章
- SQL语句通过身份证号计算年龄
SQL语句通过身份证号计算年龄 1.截取身份证号上的出生日期 身份证一般为18位数和15位数 18位数身份证的第7-10位数是出生年份,第11-14位数是出生月日,所以18位身份证的年龄计算如下 su ...
- js从身份证号中获取出生日期和性别
今天,在做移动端的项目中,按照设计稿的要求,是可以让用户自己输入出生日期的,我还很认真的用了刚刚知道的html5表单的日期类型,本想着终于不用日期插件就可以实现用户选择自己的出生日期了,可结果老大说, ...
- sql语句——根据身份证号判断男女
根据身份证判断男女的规则:二代身份证为18位,判断倒数第二位,第二位若为奇数,性别为男:偶数则为女 一代身份证为15为,判断倒数第一位,规则同上. update 表名 set 表名.字段名= case ...
- sql语句将身份证号数字转换成特殊字符
SELECT Tname , STUFF(Idcard,,,'*********') as Idcard,Completion from demo
- 从身份证号提取生日并更新到生日字段中的SQL语句
1:根据身份证号 更新 生日字段 SQL update 学生信息 ,)+,)+,) 2:根据身份证号 更新 性别字段 SQL update 学生信息 set 性别='男' and substring( ...
- sql server 根据身份证号计算出生日期和年龄的存储过程
我这边有一个业务,需要客户填写身份证号,自动计算他的出生日期和年龄 在sql中,具体的存储过程实现是这样的: /******************************************** ...
- javascript根据身份证号判断精确周岁年龄
前言: 根据身份证号判断精确周岁年龄,可以精确到天,即周岁以生日当天为准,生日当天周岁+1,少一天则不加. 实现方法: <!DOCTYPE html> <html> <h ...
- sql语句判断身份证性别等
SELECT t.card_number ,) AS "省份", SUBSTR(t.card_number,,) "出生年月", SUBSTR(t.card_n ...
- 教你一招:根据身份证号计算出生年月和年龄 text函数和mid函数混用 datedif函数和today函数混用
在电子表格Excel中,使用text函数和mid函数混用,根据身份证号计算出生年月: =text(mid(A2,,),"0!/00!/00") #0!/00!/00 为日期的格式# ...
随机推荐
- go语言练习:结构体
package main import "fmt" type book struct { title string author string page int } func ma ...
- UIAutomator环境搭建
目录 下载.安装JDK&配置Java环境变量 下载.安装SDK.ADT&配置Android环境变量 下载.安装ANT&配置ANT环境变量 创建UIAutomator工程 UIA ...
- 如何在 Azure 中均衡 Windows 虚拟机负载以创建具有高可用性的应用程序
负载均衡通过将传入请求分布到多个虚拟机来提供更高级别的可用性. 本教程介绍了 Azure 负载均衡器的不同组件,这些组件用于分发流量和提供高可用性. 你将学习如何执行以下操作: 创建 Azure 负载 ...
- 浅析C#中的Attribute
原文地址:http://www.cnblogs.com/hyddd/archive/2009/07/20/1526777.html 一.什么是Attribute 先看下面的三段代码: 1.自定义Att ...
- SpringMVC_JDBC
链接:https://pan.baidu.com/s/1a8Aht1eIeRYGb78X9v3ubA 密码:h2zy 未完,待续...
- GridBagLayout布局管理器应用详解
http://www.cnblogs.com/kungfupanda/p/7220217.html GridBagLayout布局管理器应用详解 很多情况下,我们已经不需要通过编写代码来实现一个应用程 ...
- October 28th, 2017 Week 43rd Saturday
All I ever wanted was a single thing worth fighting for. 我想要的只不过是一件能让我奋不顾身的事业. Stop complaining the ...
- Alpha- 事后诸葛亮(麻瓜制造者)
目录 预期计划 现实进展 团队体会 成员分工及工作量比例 会议总结 预期计划 在Alpha阶段开始之前,我们的预期计划是:从用户登录,发布商品.发布求购信息的基本功能开始做起.用户登录使用输入教务处的 ...
- 【Ansible 文档】【译文】常见问题
http://docs.ansible.com/ansible/latest/faq.html 如何为一个task或者整个Playbook设置PATH或者任意其他环境变量? 通过environment ...
- H5页面meta标签小结:
<meta name="viewport" content="width=device-width,user-scalable=no"> <m ...