我有如下所示的关系,员工和培训, 每个员工都可以参加任何培训,因此它是一个基本的M:M到1:M M:1的东西。
我有一个组合框来选择一个员工,我想要两个列出已完成培训和可用培训的列表框
像这样:
然后有两个按钮从一个列表框移动到另一个列表框并相应地更改记录。
我已经查询列出了员工参与的所有培训:
SELECT Training.Name, Training.Trainer, Training.Cost, Training.Type, Training.[Length(Day)]
FROM Training INNER JOIN Participation ON Training.[Training ID] = Participation.Training
WHERE (((Participation.Employee)=[Forms]![Add Training 2]![cboEmp]))
ORDER BY Training.Name;
我在选择所有培训并过滤掉上面已经在SQL查询中选择的培训时遇到了一个问题,一个简单的EXCEPT会起作用,但ACCESS不支持它。
这就是我想要的:
SELECT Training.Name, Training.Trainer, Training.Cost, Training.Type, Training.[Length(Day)]
FROM Training
EXCEPT
SELECT Training.Name, Training.Trainer, Training.Cost, Training.Type, Training.[Length(Day)]=
FROM Training INNER JOIN Participation ON Training.[Training ID] = Participation.Training
WHERE (((Participation.Employee)=[Forms]![Add Training 2]![cboEmp]))
ORDER BY Training.Name;
答案 0 :(得分:1)
您可以使用not exists
或not in
:
SELECT Training.Name, Training.Trainer, Training.Cost, Training.Type, Training.[Length(Day)]
FROM Training
WHERE Training.TrainingId NOT IN (SELECT Participation.Training
FROM Participation
WHERE Participation.Employee = [Forms]![Add Training 2]![cboEmp]
)
ORDER BY Training.Name;