简体   繁体   中英

Creating a date and finding time difference in an Oracle SQL query

I'm having some trouble finding the length of experience using an incomplete date in my table. I have it working for finding someone's age, but I have not been sucessful in calculating their length of experience.

The grad year is just a four digit year, so we are calculating as if they graduated on 1/1/YYYY. But everything I have tried is not working.

SELECT userID, 
birthdate,
to_char((sysdate-birthdate)/365.25,'00.00')  as Age,
graduationYear,
to_char((sysdate-??????)/365.25,'00.00')  as Experience
FROM MyTable
SELECT userID, 
       birthdate,
       to_char((sysdate-birthdate)/365.25,'00.00')  as Age,
       graduationYear,
       to_char((sysdate-TO_DATE(to_char(graduationYear)||'-01-01', 'yyyy-mm-dd'))/365.25,'00.00')  as Experience
FROM MyTable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM