首页
文章列表
交流群
文档
登录
mysql根据身份证号计算出生日期和年龄,并查询筛选
2024-10-10 22:40:38
小程序码
文章目录
热门文章
整理下php学员遇到的一些问题
431
fastadmin监听或重写删除编辑按钮事件
285
phpstudy怎么手动安装php8.3.0版本?
275
文档:一个案例学会fastadmin插件开发
148
php基础入门课程资料文档课件
134
表单验证:密码和确认密码的验证和文字提示
76
百题斩:用递归方式扁平化嵌套数组
67
百题斩:字符串的逆序函数
60
案例代码:用油猴脚本统计b站课堂课程总时长
59
使用ffmpeg把mp4转为加密后的m3u8文件
55
假设计算年龄只考虑年份的话,这样写即可 ```sql SELECT YEAR(CURDATE()) - SUBSTRING(ID_CARD, 7, 4) AS age,SUBSTRING(ID_CARD, 7, 4) as year FROM users HAVING age between 20 and 30 ``` 假如需要考虑月份和年份一起的话,可以这样写: ```sql SELECT YEAR(CURDATE()) - SUBSTRING(ID_CARD, 7, 4) - IF(SUBSTRING(ID_CARD, 10, 2) < 10, 0, 1) AS age,ID_CARD FROM users HAVING age between 20 and 30 ``` 拓展知识: 根据身份证号生成出生日期 ```sql SELECT CONCAT( SUBSTRING(ID_CARD, 7, 4), '-', SUBSTRING(ID_CARD, 11, 2), '-', SUBSTRING(ID_CARD, 13, 2) ) AS birthday,ID_CARD FROM users ``` 根据身份证号生成出生日期和年龄 ```sql SELECT @birthday:=CONCAT( SUBSTRING(ID_CARD, 7, 4), '-', SUBSTRING(ID_CARD, 11, 2), '-', SUBSTRING(ID_CARD, 13, 2) ) as birthday, TIMESTAMPDIFF(YEAR, @birthday, CURDATE()) as age,ID_CARD FROM users ```