I'm trying to figure out a query function in a Oracle SQL database.
I'm trying to have the query generate the number of years between two dates.
This is my query so far:
select "EMPLOYEE"."EMP_NUM" as "EMP_NUM",
"EMPLOYEE"."EMP_LNAME" as "EMP_LNAME",
"EMPLOYEE"."EMP_FNAME" as "EMP_FNAME",
"EMPLOYEE"."EMP_HIREDATE" as "EMP_HIREDATE",
TO_CHAR (SYSDATE, 'DD-MON-YY') as "QUERY_DATE"
from "EMPLOYEE" "EMPLOYEE"
I need a column between EMP_HIREDATE and QUERY_DATE called YEARS_EMPLOYED. Like so:
It will state for example "11" in the row if the employee has been hired that long.
I'm really at a lost on how to do this. I imagine it obvious deals with subtracting the two dates, but I'm not quite sure where to start. I imagine that maybe I have to subtract the two dates, then divide by 365? But what commands would be used for that, that will work with the above script anyways that I have so far..?