MySQL根据生日计算年龄

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);



原文地址:http://houzhiqingjava.blog.163.com/blog/static/167399507201362084525866/

你可能感兴趣的:(sql)