MySQL根据身份证获取省份 年龄 性别

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: MySQL根据身份证获取省份 年龄 性别

SQL语句

`select case left(id_card,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(id_card)=18,substring(id_card,7,4),if(length(id_card)=15,concat(‘19’,substring(id_card,7,2)),null)) as 年龄,

case if(length(id_card)=18, cast(substring(id_card,17,1) as UNSIGNED)%2, if(length(id_card)=15,cast(substring(id_card,15,1) as UNSIGNED)%2,3))

when 1 then ‘男’

when 0 then ‘女’

else ‘未知’

end as 性别

FROM user

附加一句根据身份证获取年龄并取年龄大于6岁的sql

SELECT
  * 
FROM
USER 
WHERE
  YEAR ( curdate( ) ) -
IF
  (
    length( a.id_card ) = 18,
    substring( a.id_card, 7, 4 ),
  IF
    (
      length( a.id_card ) = 15,
      concat( '19', substring( a.id_card, 7, 2 ) ),
    NULL 
    ) 
  ) >6
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
9月前
|
SQL 关系型数据库 MySQL
【MySQL】如何快速检索邮箱号以及身份证?
【MySQL】如何快速检索邮箱号以及身份证?
215 0
|
关系型数据库 MySQL
MySql 627.变更性别
MySql 627.变更性别
39 0
MySql 627.变更性别
|
关系型数据库 MySQL
MySQL练习7——查找年龄大于24的用户信息
MySQL练习7——查找年龄大于24的用户信息!
|
4天前
|
SQL 存储 关系型数据库
MySQL Cluster集群安装及使用
MySQL Cluster集群安装及使用
|
19天前
|
关系型数据库 MySQL 数据库
mysql卸载、下载、安装(window版本)
mysql卸载、下载、安装(window版本)
|
1月前
|
关系型数据库 MySQL 数据库
rds安装数据库客户端工具
安装阿里云RDS的数据库客户端涉及在本地安装对应类型(如MySQL、PostgreSQL)的客户端工具。对于MySQL,可选择MySQL Command-Line Client或图形化工具如Navicat,安装后输入RDS实例的连接参数进行连接。对于PostgreSQL,可以使用`psql`命令行工具或图形化客户端如PgAdmin。首先从阿里云控制台获取连接信息,然后按照官方文档安装客户端,最后配置客户端连接以确保遵循安全指引。
89 1
|
8天前
|
关系型数据库 MySQL 数据库
《MySQL 简易速速上手小册》第1章:MySQL 基础和安装(2024 最新版)
《MySQL 简易速速上手小册》第1章:MySQL 基础和安装(2024 最新版)
33 4
|
1月前
|
Ubuntu 关系型数据库 MySQL
Ubuntu 中apt 安装MySQL数据库
Ubuntu 中apt 安装MySQL数据库
69 0
|
1天前
|
关系型数据库 MySQL 数据安全/隐私保护
安装mysql和远程连接
安装mysql和远程连接
10 0
|
2天前
|
关系型数据库 MySQL Java
Linux 安装 JDK、MySQL、Tomcat(图文并茂)
Linux 安装 JDK、MySQL、Tomcat(图文并茂)
15 2