以下定义了两个表 test1,test2,其中字段 UID 对应于你的表中的姓名, test1 的 no 字段对应于销售金额, test2 的 NO 字段对应于 业务费用.dtm 字段对应于日期.
我在视图中加入了 dtm > 3-29 的 where 条件,你可能要根据自己的要求更改此限定.
SELECT ta.UID, ta.NOA, tb.NOB
FROM (SELECT UID, SUM([NO]) AS NOA
FROM test1
WHERE dtm > '2003-03-30'
GROUP BY uid) ta FULL OUTER JOIN
(SELECT uid, SUM([no]) AS NOB
FROM test2
WHERE dtm > '2003-03-30'
GROUP BY uid) tb ON ta.UID = tb.uid
我试了在 adp 中可以运行啊,你是在 adp 中还是 mdb 中?
或者你如此改动试一下.
SELECT ta.UID, ta.NOA, tb.NOB
FROM (SELECT UID, SUM([NO]) AS NOA
FROM test1
WHERE dtm > #2003-03-30#
GROUP BY uid) as ta FULL OUTER JOIN
(SELECT uid, SUM([no]) AS NOB
FROM test2
WHERE dtm > #2003-03-30#
GROUP BY uid) as tb ON ta.UID = tb.uid
SELECT tc.uid, ta.NOA, tb.NOB
FROM (SELECT UID, SUM([NO]) AS NOA
FROM test1
WHERE dtm > '2003-03-30'
GROUP BY uid) ta RIGHT OUTER JOIN
(SELECT uid, SUM([no]) AS NOB
FROM test2
WHERE dtm > '2003-03-30'
GROUP BY uid) tb RIGHT OUTER JOIN
(SELECT DISTINCT uid
FROM test1
WHERE dtm > '2003-03-30'
UNION
SELECT DISTINCT uid
FROM test2
WHERE dtm > '2003-03-30') tc ON tb.uid = tc.uid ON ta.UID = tc.uid