我真的希望有人可以帮我解决这个问题。我和一位同事创建了一个数据库来跟踪300多名员工的培训。我们创建了一份报告“进度报告”,以显示员工在部分培训中需要达到两年80小时的要求。每年或两年必须进行一些培训,但只应在进度报告中计算一次。这是sql查询:
SELECT [Employees Extended].Section, [Employees Extended].[Employee Name], Training.[Training Course], Training.Hours, Training.Category, Training.[Training Start Date], DLookUp("[BeginDate]","[DateIntervals]","Date()>[DateIntervals]![BeginDate]") AS BGN, DLookUp("[EndDate]","[DateIntervals]","Date()<[DateIntervals]![EndDate]") AS [END]
FROM Training INNER JOIN ([Employees Extended] INNER JOIN Employees ON [Employees Extended].[Employee ID] = Employees.[Employee ID]) ON Training.[Employee ID] = Employees.[Employee ID]
WHERE (((Training.Category)="Continuing Education") AND ((Training.[Training Start Date]) Between (DLookUp("[BeginDate]","[DateIntervals]","Date()>[DateIntervals]![BeginDate]")) And (DLookUp("[EndDate]","[DateIntervals]","Date()<[DateIntervals]![EndDate]")))) OR (((Training.[Training Course])="Privacy Training") AND ((Training.[Training Start Date]) Between (DLookUp("[BeginDate]","[DateIntervals]","Date()>[DateIntervals]![BeginDate]")) And (DLookUp("[EndDate]","[DateIntervals]","Date()<[DateIntervals]![EndDate]")))) OR (((Training.[Training Course])="Ethics Training") AND ((Training.[Training Start Date]) Between (DLookUp("[BeginDate]","[DateIntervals]","Date()>[DateIntervals]![BeginDate]")) And (DLookUp("[EndDate]","[DateIntervals]","Date()<[DateIntervals]![EndDate]")))) OR (((Training.[Training Course])="PRA Training") AND ((Training.[Training Start Date]) Between (DLookUp("[BeginDate]","[DateIntervals]","Date()>[DateIntervals]![BeginDate]")) And (DLookUp("[EndDate]","[DateIntervals]","Date()<[DateIntervals]![EndDate]"))));
我把这个查询放在一起,从我查找的不同的东西,并能够让它工作。但是,我不确定我需要做什么,或者做什么才能得到我需要的结果。
进度报告主要用于“继续教育”类别的培训。但是,还需要包括三项强制性培训(隐私培训,道德培训和PRA培训)。这三项培训将每年或两年进行一次。
有没有办法调整我已经拥有的查询只能拉出这三种培训中的一种?
答案 0 :(得分:0)
在发布这个问题后,我意识到我的查询比较困难。当我已经有一个完成它的查询时,我加入了三个表来获取我需要的信息。然后我使用MAX()只拉出一个重复记录和GroupBy将结果组合在一起。再说一遍,我不是专业人士,我不知道这是否是最佳方式。
SELECT [Training Extended (Test)].Section, [Training Extended (Test)].[Employee Name], [Training Extended (Test)].[Training Course], [Training Extended (Test)].Hours, [Training Extended (Test)].Category, Max([Training Extended (Test)].[Training Start Date]) AS [MaxOfTraining Start Date], DLookUp("[BeginDate]","[DateIntervals]","Date()>[DateIntervals]![BeginDate]") AS BGN, DLookUp("[EndDate]","[DateIntervals]","Date()<[DateIntervals]![EndDate]") AS [END]
FROM [Training Extended (Test)]
GROUP BY [Training Extended (Test)].Section, [Training Extended (Test)].[Employee Name], [Training Extended (Test)].[Training Course], [Training Extended (Test)].Hours, [Training Extended (Test)].Category
HAVING ((([Training Extended (Test)].Category)="Continuing Education") AND ((Max([Training Extended (Test)].[Training Start Date])) Between (DLookUp("[BeginDate]","[DateIntervals]","Date()>[DateIntervals]![BeginDate]")) And (DLookUp("[EndDate]","[DateIntervals]","Date()<[DateIntervals]![EndDate]")))) OR ((([Training Extended (Test)].[Training Course])="Privacy Training") AND ((Max([Training Extended (Test)].[Training Start Date])) Between (DLookUp("[BeginDate]","[DateIntervals]","Date()>[DateIntervals]![BeginDate]")) And (DLookUp("[EndDate]","[DateIntervals]","Date()<[DateIntervals]![EndDate]")))) OR ((([Training Extended (Test)].[Training Course])="Ethics Training") AND ((Max([Training Extended (Test)].[Training Start Date])) Between (DLookUp("[BeginDate]","[DateIntervals]","Date()>[DateIntervals]![BeginDate]")) And (DLookUp("[EndDate]","[DateIntervals]","Date()<[DateIntervals]![EndDate]")))) OR ((([Training Extended (Test)].[Training Course])="PRA Training") AND ((Max([Training Extended (Test)].[Training Start Date])) Between (DLookUp("[BeginDate]","[DateIntervals]","Date()>[DateIntervals]![BeginDate]")) And (DLookUp("[EndDate]","[DateIntervals]","Date()<[DateIntervals]![EndDate]"))));
答案 1 :(得分:0)
不幸的是......在对报告进行进一步审核后,此修复程序无效。我唯一能想到的就是为我试图包含的每种类型的培训创建一个查询,然后我创建了一个联合查询。