数据库通过出生日期计算年龄

Oracle
SELECT TRUNC(months_between(sysdate, birth)/12) AS age
from mytable

select TRUNC((to_char(sysdate, ‘yyyyMMdd’) - to_char(birth, ‘yyyyMMdd’)) /
10000) as age
from mytable

注:sysdate 为系统日期时间,birth 为表中出生日期字段

mysql
SELECT usertime,YEAR(NOW())-LEFT(usertime,4) AS birth
FROM ocms_user

CONCAT 联合查询
SELECT CONCAT(eq,sn) AS 联合结果 FROM s_run_log

你可能感兴趣的:(数据库)