access 怎么把多个表合成一个表
发布网友
发布时间:2022-05-05 16:24
我来回答
共1个回答
热心网友
时间:2022-06-27 18:31
联合查询+子查询【注意要联合各个表的字段名和数量都要一样】:
SELECT 号码, 部门, SUM(费用1) AS 费用1, SUM(费用2) AS 费用2, SUM(费用3) AS 费用3 FROM (
SELECT 号码, 部门, 费用1, 费用2, 费用3 FROM 表1
UNION ALL
SELECT 号码, 部门, 费用1, 费用2, 费用3 FROM 表2
UNION ALL
SELECT 号码, 部门, 费用1, 费用2, 0 AS 费用3 FROM 表3
UNION ALL
SELECT 号码, 部门, 0 AS 费用1, 0 AS 费用2, 费用3 FROM 表4) AS TEMPTABLE
GROUP BY 号码, 部门;