It should be something like:
SELECT DISTINCT studentID FROM attendant
WHERE studentID NOT IN
(SELECT DISTINCT studentID FROM attendant
WHERE Startdatum BETWEEN #1/1/2010# AND #12/31/2010#)
Вопрос
I have a table containing the columns studentID, course and start_date where studentID is unique. I want to write a query so that students that haven't gone to any courses with a start date within the year 2010 appears. My problem is that I seem to return all students that have gone to any course that isn't 2010 even though they have attended a course during 2010.
SELECT DISTINCT studentID
FROM attendant
WHERE Startdatum NOT BETWEEN #1/1/2010# AND #12/31/2010#
What I'm really asking is; Is there any way to not show a row if it contains a certain value? How?
Subquery of some sort?
Решение
It should be something like:
SELECT DISTINCT studentID FROM attendant
WHERE studentID NOT IN
(SELECT DISTINCT studentID FROM attendant
WHERE Startdatum BETWEEN #1/1/2010# AND #12/31/2010#)
Другие советы
A good way to answer this question is using the having
clause:
SELECT studentID
FROM attendant
GROUP BY studentID
HAVING sum(iif(Startdatum BETWEEN #1/1/2010# AND #12/31/2010#, 1, 0)) = 0;
The having
clause is counting the number of courses that each student took during the time frame. If there are any, then the filter fails.