我是新来的。我正试图通过视频来学习,但我已经在某种程度上被抛到了另一端。
我有一张摆满了个别检查箱的报告的桌子。每个条目都有日期、检验员编号和检查项目的数量。我是否能够创建一个MS Access查询来报告每周由单个检查人员检查的框数(按检验员编号),我可以想象每一列都是每一行(检查器)的框数之和。
到目前为止,我已经得到了一个查询,它给出了每个检查人员每个月在所有时间跨度内的数量。因此,第一栏,例如,是总结检查人员自报告开始以来每年一月的盒子数量,而不是一个单独的一月(或者我真正需要的是一个单独的一周)。这是在Access中可以做的事情,还是我过度扩展了它的使用(或者可能一起滥用它)?
当前的SQL查询:
TRANSFORM Sum(report.[Box quantity]) AS [SumOfBox quantity]
SELECT Val(report.[Inspector Number]), Sum(report.[Box quantity]) AS [Total Of Box quantity]
FROM report
GROUP BY report.[Inspector Number]
PIVOT Format([Date Issued],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
发布于 2022-04-11 12:03:13
从行和列标题的日期值中提取年份和周部分。考虑:
TRANSFORM Sum([Box quantity]) AS [SumOfBox quantity]
SELECT Val([Inspector Number]) AS InsNum, Year([Date Issued]) AS Yr, Sum([Box quantity]) AS [Total Of Box quantity]
FROM report
GROUP BY [Inspector Number], Year([Date Issued])
PIVOT DatePart("ww", [Date Issued])
如果要确保每周生成一列,可以使用IN():
In (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53)
https://stackoverflow.com/questions/71831384
复制相似问题