In order to generate running total of Sales Qty in MS Access, I used below query, it is working as expected
SELECT ID, [Product Line], DSUM(\"[Qty]\",\"[SalesDat
Rather than using domain aggregate functions (such as DSum
) which are known to be notoriously slow, I would suggest using a correlated subquery, such as the following:
select q.* from
(
select t.id, t.[product line], t.qty,
(
select sum(u.qty)
from salesdata u
where u.[product line] = t.[product line] and u.id <= t.id
) as runningtotal
from salesdata t
where t.[product line] like "*Electronics*"
) q
where q.runningtotal < 100
EDIT:
select t.*, q.runningtotal from salesdata t inner join
(
select t.id,
(
select sum(u.qty)
from salesdata u
where u.[product line] like "*Electronics*" and u.id <= t.id
) as runningtotal
from salesdata t
) q on t.id = q.id
where q.runningtotal < 100 and t.[product line] like "*Electronics*"