我在Access中设置了以下两个查询。每个查询每个组织只有1行,组织名称在两个查询中是一致的。
查询A(基于表A的预算模型)
Org, Jan, Feb, ... Dec, Total
-----------------------------
A, $68, $25, ... $51, $809
B, $23, $39, ... $13, $423
...
E, $11, $90, ... $84, $789
查询B(基于表B的预算模型)
Org, Jan, Feb, ... Dec, Total
-----------------------------
A, $67, $25, ... $70, $821
B, $23, $39, ... $13, $423
...
E, $15, $45, ... $71, $755
如何创建包含以下所有信息的报告?我很麻烦将两个查询汇总在一起,减去它们的值,然后最终在同一个报表/查询中显示总计行。
Jan, Feb, ... Dec, Total
Org A:
Model A: $68, $25, ..., $51, $809
Model B: $67, $25, ..., $70, $821
A - B : $ 1, $ 0, ..., ($19), ($12)
Org B:
Model A: $23, $39, ..., $13, $423
Model B: $23, $39, ..., $13, $423
A - B : $ 0, $ 0, ..., $ 0, $ 0
...
Org E:
Model A: $11, $90, ..., $84, $789
Model B: $15, $45, ..., $71, $755
A - B :($ 4),$45, ..., $13, $ 34
-------------------------------------------
Totals:
Model A: $102, $154, ..., $148, $2021
Model B: $105, $109, ..., $154, $1999
A - B :($ 3), $45, ..., ($ 6), $ 22
答案 0 :(得分:1)
如果使用一组值乘以-1创建UNION查询,则可以使用组织上的组和来获取报表中的减法。报告向导将为您执行此操作。
SELECT "a" as Source, qa.Org,
qa.Jan, qa.Feb, qa.Dec, qa.Total
FROM qa
UNION ALL
SELECT "b" as Source, qb.Org,
qb.Jan * -1, qb.Feb * -1, qb.Dec * -1, qb.Total * -1
FROM qb
您可以按来源分组以创建可以作为子报告包含的摘要。