1.数据表里仅仅有生日字段,想计算出其年龄的mysql语句:
SELECT *,DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW( ))-TO_DAYS(生日字段)),‘%Y‘)+0 AS age FROM 表名;
时间: 2024-12-21 14:46:21
1.数据表里仅仅有生日字段,想计算出其年龄的mysql语句:
SELECT *,DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW( ))-TO_DAYS(生日字段)),‘%Y‘)+0 AS age FROM 表名;