mysql根据出生日期计算年龄

DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(BirthDate)) ,'%Y') +0 AS Age


SELECT a.*,DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(BirthDate)) ,'%Y') +0 AS Age,b.City,c.Name
FROM  `employee_master` AS a 
LEFT JOIN `city_master` AS b ON(a.CtyID=b.CityID) 
LEFT JOIN `branch_master` AS c ON(a.BrnID=c.BrnID) WHERE 1=1


SELECT a.*,DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(BirthDate)) ,'%Y') +0 AS Age,b.City,c.Name
FROM  `employee_master` AS a 
LEFT JOIN `city_master` AS b ON(a.CtyID=b.CityID) 
LEFT JOIN `branch_master` AS c ON(a.BrnID=c.BrnID) WHERE 1=1

你可能感兴趣的:(mysql)