In MS Access, I have a query where I want to use a column in the outer query as a condition in the inner query:
SELECT P.FirstName, P.LastName, Count(A.attendance_date) AS CountOfattendance_date, First(A.attendance_date) AS FirstOfattendance_date, (SELECT COUNT (*) FROM(SELECT DISTINCT attendance_date FROM tblEventAttendance AS B WHERE B.event_id=8 AND B.attendance_date >= FirstOfattendance_date) ) AS total FROM tblPeople AS P INNER JOIN tblEventAttendance AS A ON P.ID = A.people_id WHERE A.event_id=8 GROUP BY P.FirstName, P.LastName ;
The key point is FirstOfattendance_date – I want the comparison deep in the subselect to use the value in each iteration of the master select. Obviously this doesn’t work, it asks me for the value of FirstOfattendance_date when I try to run it.
I’d like to do this without resorting to VB code… any ideas?
How about: