Write a command in sqlplus to find how long each employee has worked for the company. The answer can be given in fractions of years.
Let Employee be a table containing the fields employee_id, employee_name, employee_hiredate where employee_id and varchar_name is of varchar type and hiredate is of date type.
SQL command to find how long each employee has worked for the company :
select employee_id, employee_name, round((months_between(trunc(sysdate), trunc(hiredate))/12),2) years from Employee;
where sysdate returns the the current date and months_between returns the the number of months between sysdate and hiredate. The result is divided by 12 to return the number of years. round method rounds the difference to 2 digits after decimal point.
Get Answers For Free
Most questions answered within 1 hours.