我已经搜索过这个问题的答案,但似乎找不到任何可以在交叉表中进行独特计数的工作。我能找到的最接近的是:select count(myField)from(从myTable中选择不同的myField),但我一直收到错误。
培训类型在列中,日期在行中(格式化为月份,因此我可以将季度或个别月份分开),理想情况下,我将这些值作为由其种植者记录ID标识的唯一受训者的数量。它目前显示所有曾多次接受过相同培训的学员。
任何帮助将不胜感激!下面是SQL。谢谢你的时间!
SQL:
TRANSFORM Count([TDB - Master - Trainee Attendence].[Grower Record ID]) AS [CountOfGrower Record ID]
SELECT Format([Dat Fòmasyon],'mm/yy') AS Months, Count([TDB - Master - Trainee Attendence].[Grower Record ID]) AS [Total Of Grower Record ID]
FROM [TDB - Master - Trainee Attendence]
WHERE (((Format([Dat Fòmasyon],'mm/yy'))="01/13" Or (Format([Dat Fòmasyon],'mm/yy'))="02/13"))
GROUP BY Format([Dat Fòmasyon],'mm/yy')
PIVOT [TDB - Master - Trainee Attendence].[Tit Fòmasyon an];
答案 0 :(得分:0)
我建议你创建一个想要报告的数据的查询(大概):
SELECT DISTINCT [Grower Record ID], [Dat Fomasyon], [Tit Fomasyon an]
FROM [TDB - Master - Trainee Attendance]
然后使用此查询作为数据源生成数据透视表。
现在我并不完全熟悉访问的细微差别,并且不确定您是否可以从查询中生成数据透视表,但如果没有,我建议您更改代码(在表单的克隆中)来执行同样的事情,用[别名]查询替换from子句(并删除对其他子句中出现的基表的引用):
TRANSFORM Count([Grower Record ID] AS [CountOfGrower Record ID]
SELECT Format([Dat Fomasyon], 'mm/yy' AS Months, Count([Grower Record ID]) as [Total of Grower Record ID]
FROM (SELECT DISTINCT [Grower Record ID], [Dat Fomasyon], [Tit Fomasyon]
FROM [TDB - Master - Trainee Attendance]) Uniq
WHERE Format([Dat Fòmasyon],'mm/yy') = "01/13" Or Format([Dat Fòmasyon],'mm/yy' = "02/13"
GROUP BY Format([Dat Fòmasyon],'mm/yy')
PIVOT [Tit Fòmasyon an]
注意,在重写自生成以来编辑的逻辑时,我无法思考,因为计数的名称(在“AS”之后的[]中)在变换和选择行中是不同的。我不希望这很重要,不过在访问中你永远不会知道。
希望这会有所帮助......
如果这有助于你,请标记为答案。