我的表格如下:
Field1 Field2 Blank Fail Pass Date
a 1 0 20 40 170101
a 2 1 19 99 170101
b 1 0 54 24 170101
c 3 1 24 30 170101
a 1 0 11 19 170102
b 2 0 21 266 170102
a 1 2 10 40 170103
....
用户然后选择他们想要显示的日期范围,我希望我的结果如下:
Field1 Field2 0101_B 0101_F 0101_P 0102_B 0102_F 0102_P 0103_B 0103_F 0103_P
a 1 0 20 40 0 11 19 2 10 40
a 2 1 19 99
b 1 0 54 24
c 3 1 24 30
b 2 0 21 266
任何帮助真的很感激!
答案 0 :(得分:0)
选项:
UNION查询作为CROSSTAB的来源 - 参数确实应该引用表单上的控件。
PARAMETERS StartDate Long, EndDate Long;
TRANSFORM Sum(Q.Data) AS SumOfData
SELECT Q.Field1, Q.Field2, Q.Yr
FROM (SELECT Field1, Field2, Blank AS Data, "B" AS Source, [Date], Mid([Date],3) & "_B" AS MonDayCat, Int(Left([Date],2)) AS Yr FROM Table1
UNION SELECT Field1, Field2, Pass, "P", [Date], Mid([Date],3) & "_P", Int(Left([Date],2)) AS Yr FROM Table1
UNION SELECT Field1, Field2, Fail, "F", [Date], Mid([Date],3) & "_F", Int(Left([Date],2)) AS Yr FROM Table1) AS Q
WHERE (((Q.Date) Between [StartDate] And [EndDate]))
GROUP BY Q.Field1, Q.Field2, Q.Yr
PIVOT Q.MonDayCat;
然后三个CROSSTAB查询加入CROSSTABS
VBA程序将记录写入'临时'表
如果每天都有数据,这些选项都不会允许一整年的数据 - 最多2.5个月。建立一个基于CROSSTAB永久运行的稳定报告并不容易。查看http://allenbrowne.com/ser-67.html#ColHead。