試一下這個: 從1996年1月1日到1999年12月31日之間每隔50天的入職人數。select count(tm.sd),tm.sd from employees em, (select to_date('19960101000000','yyyymmddhh24miss') + ((level - 1) * 50) sd from dual connect by level <= ceil((to_date('19991231235959','yyyymmddhh24miss') - to_date('19960101000000','yyyymmddhh24miss')) / 50) ) tm where EM.HIRE_DATE - tm.sd between 0 and 50 and em.hire_date between to_date('19960101000000','yyyymmddhh24miss') and to_date('19991231235959','yyyymmddhh24miss') group by tm.sd order by tm.sd
20100101 -- 20100401 每隔10天的时间段 select * from ( select to_date('20100101','yyyymmdd') + ((level - 1) * 10) sd from dual connect by level <= ceil((to_date('20100401','yyyymmddhh24miss') - to_date('20100101','yyyymmddhh24miss')) / 10) ) order by sd
從1996年1月1日到1999年12月31日之間每隔50天的入職人數。select count(tm.sd),tm.sd
from employees em,
(select to_date('19960101000000','yyyymmddhh24miss') + ((level - 1) * 50) sd
from dual
connect by level <= ceil((to_date('19991231235959','yyyymmddhh24miss') - to_date('19960101000000','yyyymmddhh24miss')) / 50)
) tm
where EM.HIRE_DATE - tm.sd between 0 and 50
and em.hire_date between to_date('19960101000000','yyyymmddhh24miss') and to_date('19991231235959','yyyymmddhh24miss')
group by tm.sd
order by tm.sd
20100101 -- 20100401 每隔10天的时间段
select * from
(
select to_date('20100101','yyyymmdd') + ((level - 1) * 10) sd
from dual
connect by level <= ceil((to_date('20100401','yyyymmddhh24miss') - to_date('20100101','yyyymmddhh24miss')) / 10)
)
order by sd