日期:2014-05-17 浏览次数:20965 次
--想不出什么好方法了,输入起始时间和结束时间 with recordInfo(id,name,recorddate,workhours) as ( select 1,'sa',to_date(20120610,'yyyymmdd'),8.00 from dual union select 2,'sa',to_date(20120611,'yyyymmdd'),8.00 from dual union select 3,'root',to_date(20120611,'yyyymmdd'),9.00 from dual union select 4,'root',to_date(20120614,'yyyymmdd'),7.00 from dual union select 5,'admin',to_date(20120615,'yyyymmdd'),6.00 from dual union select 6,'sa',to_date(20120610,'yyyymmdd'),3.00 from dual ) select s.name ,s.dat , nvl(sum(rec2.workhours),0) from (select distinct (rec.name) as name, t.dat from recordInfo rec, (select to_date(replace('&&begin_dat', '-'), 'yyyymmdd') + level - 1 as dat from dual connect by level <= (to_date(replace('&&end_dat', '-'), 'yyyymmdd') - to_date(replace('&&begin_dat', '-'), 'yyyymmdd')) + 1 ) t) s left join recordInfo rec2 on (s.name = rec2.name and trunc(s.dat) = trunc(rec2.recorddate)) group by s.name , s.dat order by s.name , s.dat / sys@ORCL> / Enter value for begin_dat: 20120610 old 19: (select to_date(replace('&&begin_dat', '-'), 'yyyymmdd') + new 19: (select to_date(replace('20120610', '-'), 'yyyymmdd') + Enter value for end_dat: 20120615 old 23: (to_date(replace('&&end_dat', '-'), 'yyyymmdd') - new 23: (to_date(replace('20120615', '-'), 'yyyymmdd') - old 24: to_date(replace('&&begin_dat', '-'), 'yyyymmdd')) + 1 new 24: to_date(replace('20120610', '-'), 'yyyymmdd')) + 1 NAME DAT NVL(SUM(REC2.WORKHOURS),0) ----- ---------- -------------------------- admin 2012-06-10 0 admin 2012-06-11 0 admin 2012-06-12 0 admin 2012-06-13 0 admin 2012-06-14 0 admin 2012-06-15 6 root 2012-06-10 0 root 2012-06-11 9 root 2012-06-12 0 root 2012-06-13 0 root 2012-06-14 7 root 2012-06-15 0 sa 2012-06-10 11 sa 2012-06-11 8 sa 2012-06-12 0 sa 2012-06-13 0 sa 2012-06-14 0 sa 2012-06-15 0
------解决方案--------------------
貌似是写复杂了点 还没怎么想 应该还有简单的吧 大概就这思路了
select t3.name,t3.r_d