You can get what you want with a correlated subquery.
SELECT
a1.agentID,
a1.incurrredDate,
a1.points,
a1.OneFallOff,
a1.TwoFallOff
(
SELECT Sum(a2.TwoFallOff)
FROM attendanceView AS a2
WHERE
a2.agentID = a1.agentID
AND a2.incurrredDate <= a1.incurrredDate
) AS total
FROM attendanceView AS a1;
You could also do it with DSum
, but then you need to use delimiters with agentID
and incurrredDate
in the DSum
WhereCondition option. It seems like more effort, and I found it more error-prone, than the subquery approach.
SELECT
a.agentID,
a.incurrredDate,
a.points,
a.OneFallOff,
a.TwoFallOff,
DSum
(
"TwoFallOff", "attendanceView",
"agentID = '" & a.agentID & "' " &
"AND incurrredDate <= " &
Format(a.incurrredDate, "#yyyy-m-d#")
) AS total
FROM attendanceView AS a;
Both queries return your requested results using your sample data in Access 2007.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…