萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> asp編程 >> asp+access按年,按月統計數據

asp+access按年,按月統計數據

asp教程+access按年,按月統計數據
/*
字段: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);

copyright © 萬盛學電腦網 all rights reserved