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 为日期的格式# ...
随机推荐
- the database needs something to populate existing rows.
这是我在使用Django进行models编写时的一个错误. 解决办法: 为其指定一个默认值即可 object_id = models.CharField(max_length=50, default= ...
- 在web中如何调整上传过的图片方向 (exif)
前提: 相机中拍的照片放到web上不会自动识别方向,如有些竖向显示的照片放到web上横向显示.这些照片在windows上是正确显示的.但是web不会自动旋转照片到正确方向.下面我们通过两种方法来实现这 ...
- 试试SQLServer 2014的内存优化表(转载)
SQL Server2014存储引擎:行存储引擎,列存储引擎,内存引擎 SQL Server 2014中的内存引擎(代号为Hekaton)将OLTP提升到了新的高度. 现在,存储引擎已整合进当前的数据 ...
- myeclipse 10配置jboss 7.1.1无法启动Error: Could not create the Java Virtual Machine
myeclipse 10中配置jboss 7.1.1,多写了个server name,结果死活启动不了.后来,发现了这个细节. 错误显示: 错误源头: 删掉Server name后,可以完美启动 小问 ...
- Windows7系统中怎么Ping端口?利用telnet命令Ping 端口的方法
telnet www.baidu.com 80 端口打开的情况下,链接成功,则进入Telnet页面(全黑的),证明端口可用.
- CheckTimeWait.bat实现windows下的TimeWait检查
原文链接: http://www.lookdaima.com/WebForms/WebPages/Blanks/Pm/Docs/DocItemDetail.aspx?id=c7bff196-cd9c- ...
- Linux运维之--LVS、Nginx、HAproxy有什么区别?
LVS: 是基于四层的转发 HAproxy: 是基于四层和七层的转发,是专业的代理服务器 Nginx: 是WEB服务器,缓存服务器,又是反向代理服务器,可以做七层的转发 区别: LVS由于是基于四层的 ...
- Java集合和泛型
集合 常用的集合有ArrayList,TreeSet,HashMap,HashSet. ArrayList 最常用的集合,每次插入都在后面追加元素. TreeSet 以有序状态保持并可防止重复.当你需 ...
- Netty入门(四)ByteBuf 字节级别的操作
Netty 中使用 ByteBuf 代替 Java NIO 提供的 ByteBuffer 作为字节的容器. 一.索引 ByteBuf 提供两个指针变量支持读和写操作,读操作使用 readerInde ...
- ORA-27125: unable to create shared memory segment的解决方法(转)
ORA-27125: unable to create shared memory segment的解决方法(转) # Kernel sysctl configuration file for Red ...