【发布时间】:2014-03-31 06:16:38
【问题描述】:
我从中获取所有数据的主表是“RequestTable”(我将其缩小以使其更容易),其中我有:
ID_student
ID_professor
Date (and the three altogether are primary keys)
changeprofessor-note - if student wants to change the professor
then he/she should write in that field a sentence
why he/she wants to do the change
professor-reject-note - if the professor is not happy about the work of
the student, then he can choose not to mentor that
student anymore, leaving him without a mentor and the
student should choose another mentor later.
ID-seminar- after choosing a mentor the students
can choose the seminar they want to work on
changeofSeminar-note - if the student wants to change the seminar
then they need to write the reason why in here
(then the ID of the new seminar should be written in
the ID seminar field also)
IDapprove-reject - all approving or rejecting is going through this field
我最初的理论是学生可以连续选择导师和研讨会,但现在看起来太复杂了,因为我不知道如何在更换导师、拒绝导师、更换研讨会等之后让一切正常进行。
我设定了一个更舒服的理论,所有的学生都需要先选择导师。这样我就可以在需要时更容易获得指导数据。我在“ID_seminar”和“changeofseminar-note”下的查询中设置了“is null”,因为仅研讨会部分的任何更改都不会影响学生选择导师/教授并获得批准的行。
我实现了你的代码并得到了这个:
SELECT [requesttable].ID_Student, Max([requesttable].Datum) AS MaxOfDatum, First([requesttable].ID_Profesor) AS ID_Profesor, [requesttable].ID_status_odobrenja
FROM [requesttable]
WHERE ((([requesttable].ID_Student) Not In (SELECT [ID_Student]
FROM [requesttable]
WHERE [IDapprove-reject] IS NOT NULL )))
GROUP BY [requesttable].ID_Student, [requesttable].IDapprove-reject, [requesttable].changeseminar-note, [requesttable].ID_seminar
HAVING ((([requesttable].IDapprovereject)=1) AND (([requesttable].changeseminar-note) Is Null) AND (([requesttable].Id_seminar) Is Null))
ORDER BY [requesttable].ID_Student, Max([requesttable].Datum), First([requesttable].ID_Profesor), [requesttable].IDapproved-reject;
我得到:
3 12 1
15 11 1
55 5 1
我需要:
3 6 1
15 6 1
52 5 1 - after being rejected by mentor 10,
the student choose another mentor (id 5) and got approved.
55 5 1
以下旧信息:
我的查询到此为止,另外两个数据被设置为只显示具有空值的行来得到这个:
ID student Id professor date professor-reject-note ID accept/reject
3 12 12.11.2012 null 1
3 6 13.11.2012 null 1
52 10 12.11.2012 null 1
52 10 15.11.2012 NOT null 1
55 5 12.11.2012 null 1
我希望我的结果是
3 6 12.10.2013 null 1
15 6 7.1.2013 null 1
55 5 12.11.2012 null 1
完全排除 StudentID 52,因为教授拒绝说明意味着教授不想再指导学生。另外我对该选项中的 ID 接受/拒绝编号有疑问,也许我可以将其设置为 2 而不是 1 以使其更容易。 1 表示接受,2 表示拒绝,但如果我将其设置为 2 并排除整行,我仍然无法摆脱其他 ID 52 行。我对此有点困惑,不知道如何使它工作。
如果我将日期设置为 maxdate 并且 Id 教授按 FIRST 分组,我几乎得到了我想要的,所有数据都是正确的,除了学生 ID 52 仍然存在 - 两行。
【问题讨论】:
标签: ms-access-2007 ms-access-2010