我正在开发一个基于网络的培训管理系统,该系统为用户提供简短的测验以更新他们的知识。无论如何,我有以下数据库设计:
Employee Table: Username, Name, DivisionCode
Divisions Table: SapCode, DivisionShortcut
Quiz Table: QuizID, Title, IsSent
Question Table: QuestionID, Question, QuizID...
UserQuiz Table: UserQuizID, QuizID, Username, Score.
我能够提出一个查询,该查询仅在最后一次测验中显示所有部门中所有非参与者的姓名。我现在想要的是在已发送给用户参与的所有测验中显示非参与者的姓名。结果应按测验标题和 DivisionShortcut 分组列出。那么该怎么做呢?
我的查询:
SELECT d.DivisionShortcut, e.Name
FROM employee e
join Divisions d on (e.DivisionCode = d.SapCode)
left join (select A.QuizID, a.Username
from UserQuiz a join
(select max(QuizID) QuizID from dbo.Quiz where IsSent=1) b
on a.QuizId = b.QuizID ) c
on e.Username = c.Username
WHERE c.QuizID is null
Order By d.DivisionShortcut