MySQL 查询n年前记录

https://blog.csdn.net/qq_40012791/article/details/79985293

需求: birthday 字段存储的是 人员生日,格式是:年-月-日,如:1955年07月26日

 现要查询某个年龄段的人员信息,如:50~60 岁。

SQL 语句设计如下:

select * from table where YEAR(CURDATE())-substring(birthday,1,4) >= 50 and YEAR(CURDATE())-substring(birthday,1,4) <=60

猜你喜欢

转载自blog.csdn.net/NRlovestudy/article/details/85268131