mysql 根据生日计算年龄,并查询在18-25之间的语句
select id, DATE_FORMAT(birthday,"%Y-%m-%d") birthday, CURDATE() , (year(now())-year(birthday)-1) + ( DATE_FORMAT(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') ) as age from t_user where id in (1,55000,55001);
select (year(curdate())-year(birthday)-1+(DATE_FORMAT(birthday,'%m%d')<=(DATE_FORMAT(curdate(),'%m%d')))) as '年龄' from employee; (year(curdate())-year(birthday)-1+(DATE_FORMAT(birthday,'%m%d')<=(DATE_FORMAT(curdate(),'%m%d')))) BETWEEN 18AND 25
select (year(curdate())-year(birthday)-1+(DATE_FORMAT(birthday,'%m%d')<=(DATE_FORMAT(curdate(),'%m%d')))) as '年龄' from employee;
参考:
http://blog.csdn.net/a673341766/article/details/32321881
http://blog.csdn.net/zm2714/article/details/7896381