标签:
select SUBSTR(‘20140901‘, 1, 6) AS CALC_MONTH,
EMP.EMPLOYEE_CODE as EMPLOYEE_CODE,
EMP.EMPLOYEE_NAME AS EMPLOYEE_NAME,
EMP.EMPLOYEE_TYPE AS EMPLOYEE_TYPE,
TO_CHAR(TO_NUMBER(SUBSTR(‘20140901‘, 1, 4)) - TO_NUMBER(TO_CHAR(EMP.BIRTHDAY, ‘YYYY‘))) AS AGE, --年龄
EMP.EDUCATION_CODE as EDUCATION_CODE,--学历
nvl(TEMP.CHANNEL_TYPE,EMP.EMPLOYEE_CHANNEL),--人员渠道
nvl(TEMP.ACCURATE_START_DATE,emp.enter_date),
TEMP2.CHANNEL_DUTY--人员类别
from EPCIS_SAS_EMPLOYEE emp,
(SELECT CHN.EMPLOYEE_CODE,
CHN.CHANNEL_TYPE,
MIN(CHN.START_DATE) ACCURATE_START_DATE,
MAX(NVL(CHN.END_DATE, DATE ‘2051-01-01‘)) ACCURATE_END_DATE
FROM (SELECT EMP.EMPLOYEE_CODE,
HIS.CHANNEL_TYPE,
HIS.START_DATE,
HIS.END_DATE,
ROW_NUMBER() OVER(ORDER BY EMP.EMPLOYEE_CODE, HIS.START_DATE) - ROW_NUMBER() OVER(PARTITION BY EMP.EMPLOYEE_CODE, HIS.CHANNEL_TYPE ORDER BY EMP.EMPLOYEE_CODE, HIS.START_DATE) IND
FROM EPCIS_SAS_EMPLOYEE EMP,
EPCIS_SAS_LEVEL_HISTORY HIS
WHERE EMP.HR_CODE IS NOT NULL
AND EMP.EMPLOYEE_CODE = HIS.EMPLOYEE_CODE
) CHN
GROUP BY CHN.EMPLOYEE_CODE, CHANNEL_TYPE, IND
having MIN(CHN.START_DATE) < to_date(‘20140901‘, ‘yyyymmdd‘) and MAX(NVL(CHN.END_DATE, DATE ‘2051-01-01‘)) >= to_date(‘20141001‘, ‘yyyymmdd‘)
) TEMP,
(select EMPLOYEE_CODE,CHANNEL_DUTY from EPCIS_SAS_LEVEL_HISTORY where START_DATE < to_date(‘20140901‘, ‘yyyymmdd‘)
and NVL(END_DATE, SYSDATE) >= to_date(‘20141001‘, ‘yyyymmdd‘)
)TEMP2
where EMP.EMPLOYEE_CODE = TEMP.EMPLOYEE_CODE(+)
and EMP.EMPLOYEE_CODE = TEMP2.EMPLOYEE_CODE(+)
and EMP.HR_CODE IS NOT NULL
and EMP.ENTER_DATE < to_date(‘20140901‘, ‘yyyymmdd‘)
and NVL(EMP.LEAVE_DATE, SYSDATE) >= to_date(‘20141001‘, ‘yyyymmdd‘)
标签:
原文地址:http://www.cnblogs.com/zhangwensi/p/4740592.html