[attach]37201[/attach]
1、查询:
SELECT a.ID, a.组, a.姓名, a.配额, (select sum(b.配额) from 表2 as b
where b.ID<=a.ID and b.组=表1.组) AS 累计, 表1.总额
FROM 表1
INNER JOIN 表2 AS a ON 表1.组=a.组;
2、实得数查询:
SELECT a.ID, a.组, a.姓名, a.配额, a.累计, a.总额, IIf([累计]<=[总额],[配额],IIf(DLookUp("[累计]","[查询]","ID=" & [ID]-1 & " and 组='" & a.组 & "'")<[总额],[总额]-DLookUp("[累计]","[查询]","ID=" & [ID]-1 & " and 组='" & a.组 & "'"),0)) AS 实得数
FROM 查询 AS a;