日期:2014-05-16 浏览次数:20941 次
with T as ( select '00001' AAC001, 4 ALA040, to_date('2010-08-01','YYYY-MM-DD') ALC034 from dual union all select '00001' AAC001, 3 ALA040, to_date('2010-10-01','YYYY-MM-DD') ALC034 from dual union all select '00002' AAC001, 2 ALA040, to_date('2011-02-01','YYYY-MM-DD') ALC034 from dual union all select '00002' AAC001, 4 ALA040, to_date('2011-04-01','YYYY-MM-DD') ALC034 from dual union all select '00002' AAC001, 1 ALA040, to_date('2011-06-01','YYYY-MM-DD') ALC034 from dual ) select * from (-- 获取每人员每月份的工伤等级 select T2.AAC001 , RQB1.RQ , ( select distinct min(ALA040) from T where RQB1.RQ > to_char(ALC034,'YYYY-MM') and AAC001 = T2.AAC001) ALA040 from (-- 转为多行,从最小日期到当前月份 select to_char(add_months(mindate,rownum), 'YYYY-MM') RQ from (-- 取最小日期 select min(ALC034) mindate from T T1 ) connect by add_months(mindate,rownum) < sysdate ) RQB1, (select distinct AAC001 from T) T2 ) where ALA040 is Not Null order by AAC001,RQ