现有数据如下:
2013-1-12 15:48:22
2013-1-10 15:48:22
2013-1-4 15:48:22
2012-12-28 15:19:23
2012-12-10 15:14:00
2012-12-2 15:14:00
2012-11-20 11:49:13
2012-11-9 11:45:49
2012-11-3 11:43:31希望得到数据如下:
1月      3条
12月     3条
11月     3条
先按年份进行比较,如果年份相同再比较月份.以月份进行排序统计.
求大神指教,急...sql问题,求大神指教.急!急!急!急!

解决方案 »

  1.   

    create table t(dt date);
    select to_char(trunc(dt, 'mm'),'mm'), count(*) from t
    group by trunc(dt, 'mm') order by trunc(dt, 'mm') desc; 
      

  2.   

    select to_char(to_date(str,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm'),count(str) from test group by to_char(to_date(str,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm')
      

  3.   

    大致都是这样的,先把时间转换为月份。再依据月份进行group by 
      

  4.   

    We also have another function to do this thing.
    trunc. You can try with "trunc" too.
      

  5.   

    select to_char(ratedate,'yyyymm'),count(*) from tb_test group by to_char(ratedate,'yyyymm')