生成1-12个月的月份数据

得到1年中12个月份
SELECT TO_CHAR(ADD_MONTHS(TO_DATE('2009-01-01', 'yyyy-mm-dd'),ROWNUM - 1),'MM') MONTH
from 
ALL_OBJECTS 
where rownum <=
MONTHS_BETWEEN(TO_DATE('2009-12-01','YYYY-MM-DD'),TO_DATE('2009-01-01','YYYY-MM-DD'))+1



每月发布主题词,没有的显示为0

select c.month,sum(subcount)
from (
select b.*
    from(
    SELECT TO_CHAR(ADD_MONTHS(TO_DATE('2012-01-01', 'yyyy-mm-dd'),ROWNUM - 1),'MM') MONTH,0 subcount
    from 
    ALL_OBJECTS 
    where rownum <=
    MONTHS_BETWEEN(TO_DATE('2012-12-01','YYYY-MM-DD'),TO_DATE('2012-01-01','YYYY-MM-DD'))+1
    ) b
    union
    select a.*
    from (
    select to_char(ds.cre_date,'mm') as month,count(*) as subcount from dsp_subject ds
    where ds.status=1
   -- and to_char(ds.cre_date,'yyyy')='2012'
    group by to_char(ds.cre_date,'mm') 	
  ) a

) c
group by c.month


你可能感兴趣的:(生成1-12个月的月份数据)