SQL Select Age

SQL Select Age

SELECT trunc(months_between(sysdate,A.EFFDT)/12) “NumOfYear”
, decode( sign(trunc(sysdate) – add_months(A.EFFDT, trunc(months_between(sysdate,A.EFFDT)))), -1, trunc(mod(months_between(sysdate,A.EFFDT),12))-1
, trunc(mod(months_between(sysdate,A.EFFDT),12))) “NumOfMonth”

, decode( sign(trunc(sysdate) – add_months(A.EFFDT, trunc(months_between(sysdate,A.EFFDT)))) , -1, trunc(sysdate) – add_months(A.EFFDT, trunc(months_between(sysdate,A.EFFDT))-1)
, trunc(sysdate) – add_months(A.EFFDT, trunc(months_between(sysdate,A.EFFDT)))
) as “NumOfDay”
FROM PS_JOB A

 

Posted in SQL.