一个简单的SQL题目

来源:互联网 发布:不以规矩不成方圆知乎 编辑:程序博客网 时间:2024/06/04 18:32

有一张表,已知雇员的姓名ename,雇佣日期hiredate,要求出雇员已被雇佣的年,月,日,即雇佣了多少年,多少月,多少日。

select trunc(months_between(sysdate,hiredate)/12) year,
trunc(mod(months_between(sysdate,hiredate),12)) month,
trunc(sysdate-add_months(hiredate,months_between(sysdate,hiredate))) day
from emp
/