码迷,mamicode.com
首页 > 其他好文 > 详细

xxxxxx

时间:2015-08-18 21:17:25      阅读:410      评论:0      收藏:0      [点我收藏+]

标签:

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‘)

xxxxxx

标签:

原文地址:http://www.cnblogs.com/zhangwensi/p/4740592.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!