数据库里面现有一张表,表里面有 时间 字段 fasj (date 类型)字段内容具体到一天 例如 2010-04-22 14:01:48,,现在有需求,,求一个时间段内 按月份的记录条数;; 比如2009-04-22 14:01:48  到 2010-04-22 14:01:48 每个月的记录条数!!    有没有sql可以解决的方法,还是要写程序完成
    

解决方案 »

  1.   

    select to_char(fasj,'yyyy-mm'),count(1)
    from table1
    where fasj>=to_date('2009-4-22 14:01:48','yyyy-mm-dd hh24:mi:ss')
      and fasj<to_date('2010-4-22 14:01:48','yyyy-mm-dd hh24:mi:ss')
    group by to_char(fasj,'yyyy-mm')
      

  2.   

    select count(*)
    from t
    where fasj between date1 and date2
    group by to_char(fasj,'yyyymm')
      

  3.   

    select to_char(fasj,'yyyy-mm'),count(*) sj
    from tab
    where fasj>=to_date('2009-4-22 14:01:48','yyyy-mm-dd hh24:mi:ss')
      and fasj<to_date('2010-4-22 14:01:48','yyyy-mm-dd hh24:mi:ss')
    group by to_char(fasj,'yyyy-mm')
      

  4.   


    select to_char(fasj,'yyyymm') fasj,count(*)
    from tb
    group by to_char(fasj,'yyyymm')