转帖源于本站以前的论坛 原作者:simonwo
有预算表bug,费用表fee,把两表数据合并成一表,用以下方法:
SELECT c.日期, c.集团, c.公司, c.部门, c.费用, c.明细, nz(Sum(预算),0)+0 AS 计划, nz(Sum(收入),0)+0 AS 收, nz(Sum(支出),0)+0 AS 支
FROM [select 日期,集团,公司,部门,费用,明细,预算 , null as 收入 , null as 支出 from bug
union all select 日期,集团,公司,部门,费用,明细, null as 预算, 收入,支出 from fee]. AS c
GROUP BY c.日期, c.集团, c.公司, c.部门, c.费用, c.明细;