2012-02-03 17 views
-2

誰かが私は、MySQLデータベースに対してこのSQLを書き換えることができます(サブクエリと外側の両方が参加している)外部結合のOracle(+)記号のMySQLの変形?

**select REPORT_PACKAGE.SUBJECT_LINE, ACTIVATION_DT, PARAM_VALUE, REPORT_URL, hasCustomerDetails, 
isAccountsRolledUp FROM REPORT_PACKAGE, REPORT_PARAMETER, REPORT_DEFINITION, REPORT_PACKAGE_CONTENT, 
(select param_value as hasCustomerDetails, rpt_package_id from report_parameter 
where param_name = 'hasCustomerDetails') a, 
(select param_value isAccountsRolledUp, rpt_package_id rid from report_parameter 
where param_name = 'isAccountsRolledUp') as b 
WHERE REPORT_PACKAGE.RPT_PACKAGE_ID = REPORT_PARAMETER.RPT_PACKAGE_ID 
and param_name = 'rulePlanId' and 
REPORT_PACKAGE_CONTENT.RPT_PACKAGE_ID = REPORT_PACKAGE.RPT_PACKAGE_ID and 
REPORT_PACKAGE_CONTENT.RPT_DEF_ID = REPORT_DEFINITION.RPT_DEF_ID AND 
REPORT_URL like '%AcctNbr%' and REPORT_PACKAGE.RPT_PACKAGE_ID = a.RPT_PACKAGE_ID(+) 
and REPORT_PACKAGE.RPT_PACKAGE_ID = b.RPT_PACKAGE_ID(+);** 

私は次のことを試してみましたし、それが仕事をdidntの:

**select repa.SUBJECT_LINE, ACTIVATION_DT, PARAM_VALUE, REPORT_URL, hasCustomerDetails, 
isAccountsRolledUp FROM REPORT_PACKAGE repa 
left join (select param_value as hasCustomerDetails, rpt_package_id from report_parameter 
where param_name = 'hasCustomerDetails') as a 
left join (select param_value as isAccountsRolledUp, rpt_package_id from report_parameter 
where param_name = 'isAccountsRolledUp') as b 
left join a on repa.RPT_PACKAGE_ID = a.RPT_PACKAGE_ID 
left join b on repa.RPT_PACKAGE_ID = b.RPT_PACKAGE_ID 
inner join REPORT_PACKAGE_CONTENT repc on repa.RPT_PACKAGE_ID = repc.RPT_PACKAGE_ID 
inner join REPORT_DEFINITION rd on repc.RPT_DEF_ID = rd.RPT_DEF_ID 
where REPORT_URL like '%AcctNbr%'** 
+1

-1この問題を示す最小限の例を作成してください。 –

+0

あなたは 'a'と' b'を二度参加させようとしています。 – Wiseguy

答えて

0

私は書き換えしようとしていますクエリです。これは私が持っているものです -

SELECT 
    REPORT_PACKAGE.SUBJECT_LINE, 
    ACTIVATION_DT, 
    PARAM_VALUE, 
    REPORT_URL, 
    hasCustomerDetails, 
    isAccountsRolledUp 
FROM REPORT_PACKAGE 
    JOIN REPORT_PARAMETER 
    ON REPORT_PARAMETER.RPT_PACKAGE_ID = REPORT_PACKAGE.RPT_PACKAGE_ID 
    JOIN REPORT_PACKAGE_CONTENT 
    ON REPORT_PACKAGE_CONTENT.RPT_PACKAGE_ID = REPORT_PACKAGE.RPT_PACKAGE_ID 
    JOIN REPORT_DEFINITION 
    ON REPORT_DEFINITION.RPT_DEF_ID = REPORT_PACKAGE_CONTENT.RPT_DEF_ID 
    LEFT JOIN (SELECT param_value hasCustomerDetails, rpt_package_id FROM report_parameter WHERE param_name = 'hasCustomerDetails') a 
    ON a.RPT_PACKAGE_ID = REPORT_PACKAGE.RPT_PACKAGE_ID 
    LEFT JOIN (SELECT param_value isAccountsRolledUp, rpt_package_id rid FROM report_parameter WHERE param_name = 'isAccountsRolledUp') b 
    ON b.RPT_PACKAGE_ID = REPORT_PACKAGE.RPT_PACKAGE_ID 
WHERE 
    param_name = 'rulePlanId' 
    AND REPORT_URL like '%AcctNbr%' 

このクエリをより読みやすくするためにテーブルのエイリアスを追加してください。

+0

はDevartの魅力のように働いた!ありがとう – user1187544