一聚教程网:一个值得你收藏的教程网站

热门教程

asp+access按年,按月统计数据

时间:2022-06-29 13:50:08 编辑:袖梨 来源:一聚教程网

/*
字段:d_id(自动编号), d_je(货币型),d_sxrq(日期型)

表数据如下:

d_id   d_je   d_sxrq
1       20     2009-5-1
2       30     2009-5-6
3       10     2009-6-5
4       15     2009-6-25
5       5      2009-8-8
6       50     2009-9-9
7       20     2010-5-1
8       40     2010-5-6
9       15     2010-6-5
10      25     2010-6-25
11      55      2010-8-8
12      65     2010-9-9

想按年按月来统计:
如果选择2009年得到
月份 1 2 3 4 5  6  7  8  9  10  11 12
金额 0 0 0 0 50 25 0  5  50 0   0  0

如果选择2010年得到:
月份 1 2 3 4 5  6  7  8   9  10  11 12
金额 0 0 0 0 60 40 0  55  65  0   0  0


*/

Select Year(D_SXRQ) As Y,
       Sum(IIF(Month(D_SXRQ) = 1, D_JE, 0)) As M01,
       Sum(IIF(Month(D_SXRQ) = 2, D_JE, 0)) As M02,
       Sum(IIF(Month(D_SXRQ) = 3, D_JE, 0)) As M03,
       Sum(IIF(Month(D_SXRQ) = 4, D_JE, 0)) As M04,
       Sum(IIF(Month(D_SXRQ) = 5, D_JE, 0)) As M05,
       Sum(IIF(Month(D_SXRQ) = 6, D_JE, 0)) As M06,
       Sum(IIF(Month(D_SXRQ) = 7, D_JE, 0)) As M07,
       Sum(IIF(Month(D_SXRQ) = 8, D_JE, 0)) As M08,
       Sum(IIF(Month(D_SXRQ) = 9, D_JE, 0)) As M09,
       Sum(IIF(Month(D_SXRQ) = 10, D_JE, 0)) As M10,
       Sum(IIF(Month(D_SXRQ) = 11, D_JE, 0)) As M11,
       Sum(IIF(Month(D_SXRQ) = 12, D_JE, 0)) As M12
From   D_FY
Group  By Year(D_SXRQ);

热门栏目