前提・実現したいこと
下記SQLをサブクエリなしで実現したい
ソースコード
Oracle 11g
SELECT
A.ID,
A.TYPE,
SUM(B.AMOUNT_A) AS AMOUNT_A,
SUM(B.AMOUNT_B) AS AMOUNT_B
FROM
(
SELECT
ID,
TYPE,
FROM ID_MASTER
WHERE LOCATION = 'JPN'
AND CATEGORY = 'ABC'
GROUP BY
ID,
TYPE
) A
LEFT OUTER JOIN
(
SELECT
ID,
TYPE,
SUM(AMOUNT_A), AS AMOUNT_A,
SUM(AMOUNT_B), AS AMOUNT_B
FROM TMP_TABLE
WHERE LOCATION = 'JPN'
AND DISP_TYPE = 'ABC'
GROUP BY
ID,
TYPE,
TMP_NAME
) B
ON A.CODE = B.CODE
AND A.TYPE = B.TYPE
ORDER BY
A.ID,
A.TYPE
;
SQLのチューニング中で上記のようなSQLをサブクエリを使わず実現したいのですがハマっております。
回答2件
あなたの回答
tips
プレビュー