Oracle按间隔周统计

按非自然月归类:

select ceil(months_between(add_months(sysdate,1),sysdate))  from dual;


按非自然周分组,左侧表,left join 右侧表
 select to_char(to_date('2011-02-08', 'yyyy-mm-dd')+7*(rownum-1)  ,'yyyy-mm-dd') a ,
 to_char(case when to_date('2011-02-08', 'yyyy-mm-dd')+7*(rownum-1)+6>sysdate then sysdate else 
 to_date('2011-02-08', 'yyyy-mm-dd')+7*(rownum-1)+6 end ,'yyyy-MM-dd') as b
from all_objects where rownum<=floor((sysdate - (to_date('2011-02-08', 'yyyy-mm-dd'))) / 7)+1

你可能感兴趣的:(oracle)