oracle中如何统计中一个表的每月的记录数(表中有一个字段是Date型)?
1到12月的都要列出来,记录数为0的填0,不写存储过程尽量为以下格式
1月 5
2月 14
3月 0
4月 0
5月 9
...

解决方案 »

  1.   

    假设表T有个add_date 为date类型:
    select  extract(month from add_date) the_month
           ,count(1) as record_count 
      from t 
     group by extract(month from add_date)
      

  2.   


    select  x.the_month
           ,count(t.add_date) rec_count
      from 
    (
     select rownum the_month
       from t
      where rownum <= 12
     connect by rownum<=12
    ) x
       left outer join t
       on x.the_month = extract(month from T.add_date)
     group by x.the_month