SELECT 财务明细帐.录入日期, 财务明细帐.客户名称, Qcye([客户名称],[录入日期]) AS 月初余额, Sum(财务明细帐.出货金额) AS 出货, Sum(财务明细帐.回款金额) AS 回款, Sum(财务明细帐.折让金额) AS 折让, Format(DSum("[期初余额]+[出货金额]-[回款金额]-[折让金额]","财务明细帐","录入日期<='" & [录入日期] & "' and 客户名称='" & [客户名称] & "' "),"Standard") AS 月末余额
FROM 财务明细帐
GROUP BY 财务明细帐.录入日期, 财务明细帐.客户名称
HAVING (((财务明细帐.录入日期) Between [forms]![发生明细表窗口]![开始日期] And [forms]![发生明细表窗口]![结束日期]) AND ((财务明细帐.客户名称)=[forms]![发生明细表窗口]![客户名称]))
ORDER BY 财务明细帐.录入日期;