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