不知是不是我理解错了,不是很复杂啊,先合并,再分组统计.
SELECT A.ZD1 ,SUM(A.ZD2) AS ZD2,SUM(A.ZD3) AS ZD3 FROM (
SELECT ZD1,ZD2,0 AS ZD3 FROM 表1 UNION ALL SELECT ZD1,0 AS ZD2, ZD2 AS ZD3 FROM 表2
) A
GROUP BY A.ZD1
SELECT A.ZD1 ,SUM(A.ZD2) AS ZD2,SUM(A.ZD3) AS ZD3 FROM (
SELECT ZD1,ZD2,0 AS ZD3 FROM 表1 UNION ALL SELECT ZD1,0 AS ZD2, ZD2 AS ZD3 FROM 表2
) A
GROUP BY A.ZD1