name  money   riqi
 aa    12      2003-1-10
 c     33      2003-2-1
 c     33      2003-2-1
 c     32      2003-2-22
 b     5       2003-6-12
 d     1       2003-6-17
 e    22      2003-12-7如何统计得到如下结果:
月份  记录数 总额
1      1      12
2      3      98
3      0       0
4      0       0
5      0       0
6      2      6
7      0      0
8     0      0
9      0      0
10      0      0
11      0      0
12     1      22

解决方案 »

  1.   

    select case when substring(riqi,7,1)='-' then substring(riqi,6,1) else substring(riqi,6,2) end as Ô·Ý,count(case when substring(riqi,7,1)='-' then substring(riqi,6,1) else substring(riqi,6,2) end) as ¼Ç¼Êý,sum(money) from ±í group by (case when substring(riqi,7,1)='-' then substring(riqi,6,1) else substring(riqi,6,2) end)
      

  2.   

    select case when substring(riqi,7,1)='-' then substring(riqi,6,1) else substring(riqi,6,2) end as 月份,count(case when substring(riqi,7,1)='-' then substring(riqi,6,1) else substring(riqi,6,2) end) as 记录数,sum(money) as 总额 from 表 group by (case when substring(riqi,7,1)='-' then substring(riqi,6,1) else substring(riqi,6,2) end)
      

  3.   

    说明一下:access的数据库,在加10分!