以下查询返回:
SELECT AGE(cast(dob AS date)) FROM mas_patient_details; age ---------- 39 years 5 mons 19 days 13 years 2 days 69 years 2 days 41 years 11 mons 25 days
此查询返回:
SELECT age(cast(dob as date)) FROM mas_patient_details WHERE age <= 59; age ---------- 39 years 5 mons 19 days 13 years 2 days 69 years 2 days 41 years 11 mons 25
如果列fu的数据类型为DATE,则可以使用
原文链接:https://www.f2er.com/postgresql/192168.htmlSELECT EXTRACT(YEAR FROM fu) FROM mydate;
如果是varchar,则使用to_date()将其转换为日期
SELECT EXTRACT(YEAR FROM to_date(fu,<your pattern>)) FROM mydate;
在你的情况下:
select EXTRACT(YEAR FROM age(cast(dob as date))) from mas_patient_details where age <= 59;