从SQL表中减去当前年份

时间:2014-12-26 15:19:06

标签: sql oracle tsql oracle11g

如何从表中减去当前年份。

我有一个包含列VehicleYear的表格。因此,我只需从VehicleYear中减去当前年份即可获得VehicleAge

我尝试了以下查询,但由于SYSDATE似乎反映了添加行的日期,因此无效。

SELECT V. VEHICLENAME, (SYSDATE - V.VEHICLEYEAR) AS CURRENTAGE
FROM VEHICLE V

1 个答案:

答案 0 :(得分:1)

您可以运行此查询以从两个日期中减去年份

SELECT VEHICLENAME, 
       EXTRACT(YEAR FROM sysdate) - EXTRACT(YEAR FROM VehicleYear) AS CURRENTAGE
FROM VEHICLE;

SQL Fiddle DEMO