|
間違えていました。正しくは以下のつもりでした。
SELECT
Col1,
Col2,
Col3,
Sum(Col4) + Sum(Col5)
FROM(
SELECT Col1,Col2,Col3,SUM(Col4) AS Col4, 0 as Col5
FROM TBL_AAA
WHERE
Col1 IS NOT NULL
GROUP BY Col1,Col2,Col3
UNION
SELECT Col1,Col2,Col3, 0 as Col4, SUM(Col5) AS Col5
FROM TBL_BBB
WHERE
Col1 IS NOT NULL
GROUP BY Col1,Col2,Col3
) as T
GROUP BY Col1,Col2,Col3
もしくは、
SELECT
Col1,
Col2,
Col3,
Sum(Col4)
FROM(
SELECT Col1,Col2,Col3,SUM(Col4) AS Col4
FROM TBL_AAA
WHERE
Col1 IS NOT NULL
GROUP BY Col1,Col2,Col3
UNION
SELECT Col1,Col2,Col3, SUM(Col5) AS Col4
FROM TBL_BBB
WHERE
Col1 IS NOT NULL
GROUP BY Col1,Col2,Col3
) as T
GROUP BY Col1,Col2,Col3
|