0

最適化する必要がある SQL クエリがあり、7 月 1 日から 8 月 20 日までcp_ex_dtフィールドをループします。現在、日付ごとに個別に実行し、出力をcsvファイルに保存する必要があります。誰かがこれを実行するための最良の方法を提案できますか? ラピッド SQL で使用できるものはありますか? 私の会社ではJavaの実行が許可されていないことに注意してください。

ご検討いただきありがとうございます。

    SELECT A.S_A
      ,C.I_N
      ,C.P_A_I
      ,C.P_A_I_TYPE
      ,C.C_C    
      ,'Tel'      
      ,A.T_T AS T_T_Tel      
      ,A.D_A AS D_A_Tel      
      ,A.C_E_D AS E_D_Tel
      ,A.C_P_D AS P_D_Tel      
      ,'BBG'      
      ,D.T_T AS T_T_BB      
      ,D.D_A AS D_A_BB      
      ,D.C_E_D AS E_D_BB
      ,D.C_P_D AS P_D_BB      
      ,'Ext'     
      ,E.T_T AS T_T_Ext      
      ,E.D_A AS D_A_Ext      
      ,E.C_E_D AS E_D_Ext
      ,E.C_P_D AS P_D_Ext      
FROM TO.CP_A_HIS A
    ,PA_MA.IN B
    ,SE.SE_MA C
    ,TO.CP_A_HIS D
    ,TO.CP_A_HIS E
WHERE A.T_T = 'CASHDIV'
AND A.C_S = 'PD'
AND A.S_A = C.S_A
AND A.S_I_INST = B.INST
AND A.CP_EX_DT = '1-Jul-2014'  
AND A.S_I_INST = 46 
AND A.S_A = D.S_A(+)
AND A.T_T = D.T_T(+)
AND A.CP_EX_DT = D.CP_EX_DT(+)
AND D.C_S(+) = 'PD'
AND D.S_I_INST(+) = 45 
AND (A.CP_REA = 'REG'
AND D.CP_REA(+) IN ('final','REG','REG cash','partnership dst'))
AND D.UPDATE_DATE(+) > '16-Apr-2014'
AND A.S_A = E.S_A(+)
AND A.T_T = E.T_T(+)
AND A.CP_EX_DT = E.CP_EX_DT(+)
AND E.C_S(+) = 'PD'
AND E.S_I_INST(+) = 51
AND A.CP_REA = E.CP_REA(+)

UNION
SELECT A.S_A
      ,C.I_N
      ,C.P_A_I
      ,C.P_A_I_TYPE
      ,C.C_C
      ,'Tel'      
      ,A.T_T AS T_T_Tel      
      ,A.D_A AS D_A_Tel      
      ,A.C_E_D AS E_D_Tel
      ,A.C_P_D AS P_D_Tel     
      ,'BBG'      
      ,D.T_T AS T_T_BB     
      ,D.D_A AS D_A_BB      
      ,D.C_E_D AS E_D_BB
      ,D.C_P_D AS P_D_BB      
      ,'Ext'      
      ,E.T_T AS T_T_Ext      
      ,E.D_A AS D_A_Ext      
      ,E.C_E_D AS E_D_Ext
      ,E.C_P_D AS P_D_Ext      
FROM TO.CP_A_HIS A
    ,PA_MA.IN B
    ,SE.SE_MA C
    ,TO.CP_A_HIS D
    ,TO.CP_A_HIS E
WHERE A.T_T = 'CASHDIV'
AND A.C_S = 'PD'
AND A.S_A = C.S_A
AND A.S_I_INST = B.INST
AND A.CP_EX_DT = '1-Jul-2014'  
AND A.S_I_INST = 46 
AND A.S_A = D.S_A(+)
AND A.T_T = D.T_T(+)
AND A.CP_EX_DT = D.CP_EX_DT(+)
AND D.C_S(+) = 'PD'
AND D.S_I_INST(+) = 45 
AND (A.CP_REA = 'SPECIAL'
AND D.CP_REA(+) IN ('special cash','SPECIAL'))
AND D.UPDATE_DATE(+) > '16-Apr-2014'
AND A.S_A = E.S_A(+)
AND A.T_T = E.T_T(+)
AND A.CP_EX_DT = E.CP_EX_DT(+)
AND E.C_S(+) = 'PD'
AND E.S_I_INST(+) = 51
AND A.CP_REA = E.CP_REA(+)

UNION
SELECT D.S_A
      ,C.I_N
      ,C.P_A_I
      ,C.P_A_I_TYPE
      ,C.C_C
      ,'Tel'      
      ,A.T_T AS T_T_Tel      
      ,A.D_A AS D_A_Tel      
      ,A.C_E_D AS E_D_Tel
      ,A.C_P_D AS P_D_Tel      
      ,'BBG'      
      ,D.T_T AS T_T_BB      
      ,D.D_A AS D_A_BB      
      ,D.C_E_D AS E_D_BB
      ,D.C_P_D AS P_D_BB      
      ,'Ext'      
      ,E.T_T AS T_T_Ext      
      ,E.D_A AS D_A_Ext      
      ,E.C_E_D AS E_D_Ext
      ,E.C_P_D AS P_D_Ext      
FROM TO.CP_A_HIS A
    ,PA_MA.IN B
    ,SE.SE_MA C
    ,TO.CP_A_HIS D
    ,TO.CP_A_HIS E
WHERE D.T_T = 'CASHDIV'
AND D.C_S = 'PD'
AND D.S_A = C.S_A
AND D.S_I_INST = B.INST
AND D.CP_EX_DT = '1-Jul-2014'  
AND D.S_I_INST = 45 
AND A.S_A(+) = D.S_A
AND A.T_T(+) = D.T_T
AND A.CP_EX_DT(+) = D.CP_EX_DT
AND A.C_S(+) = 'PD'
AND A.S_I_INST(+) = 46 
AND (A.CP_REA(+) = 'SPECIAL'
AND D.CP_REA IN ('special cash','SPECIAL'))
AND D.UPDATE_DATE > '16-Apr-2014'
AND A.INST IS NULL
AND D.S_A = E.S_A(+)
AND D.T_T = E.T_T(+)
AND D.CP_EX_DT = E.CP_EX_DT(+)
AND E.C_S(+) = 'PD'
AND E.S_I_INST(+) = 51
AND (E.CP_REA(+) = 'SPECIAL'
AND D.CP_REA IN ('special cash','SPECIAL'))

UNION
SELECT D.S_A
      ,C.I_N
      ,C.P_A_I
      ,C.P_A_I_TYPE
      ,C.C_C
      ,'Tel'      
      ,A.T_T AS T_T_Tel      
      ,A.D_A AS D_A_Tel      
      ,A.C_E_D AS E_D_Tel
      ,A.C_P_D AS P_D_Tel      
      ,'BBG'      
      ,D.T_T AS T_T_BB      
      ,D.D_A AS D_A_BB      
      ,D.C_E_D AS E_D_BB
      ,D.C_P_D AS P_D_BB      
      ,'Ext'     
      ,E.T_T AS T_T_Ext     
      ,E.D_A AS D_A_Ext      
      ,E.C_E_D AS E_D_Ext
      ,E.C_P_D AS P_D_Ext     
FROM TO.CP_A_HIS A
    ,PA_MA.IN B
    ,SE.SE_MA C
    ,TO.CP_A_HIS D
    ,TO.CP_A_HIS E
WHERE D.T_T = 'CASHDIV'
AND D.C_S = 'PD'
AND D.S_A = C.S_A
AND D.S_I_INST = B.INST
AND D.CP_EX_DT = '1-Jul-2014'  
AND D.S_I_INST = 45 
AND A.S_A(+) = D.S_A
AND A.T_T(+) = D.T_T
AND A.CP_EX_DT(+) = D.CP_EX_DT
AND A.C_S(+) = 'PD'
AND A.S_I_INST(+) = 46 
AND (A.CP_REA(+) = 'REG'
AND D.CP_REA IN ('final','REG','REG cash','partnership dst'))
AND D.UPDATE_DATE > '16-Apr-2014'
AND A.INST IS NULL
AND D.S_A = E.S_A(+)
AND D.T_T = E.T_T(+)
AND D.CP_EX_DT = E.CP_EX_DT(+)
AND E.C_S(+) = 'PD'
AND E.S_I_INST(+) = 51
AND (E.CP_REA(+) = 'REG'
AND D.CP_REA IN ('final','REG','REG cash','partnership dst'))
4

1 に答える 1

0

最初の 2 つの部分からなるユニオン クエリは、"D" エイリアスに関連する "REG" エントリと "SPECIAL" エントリを除いてほとんど同じです。これらの 2 つは、最初の選択を使用して単純化できますが、次の領域を変更します。

  AND D.S_I_INST(+) = 45 
  AND (
         (     A.CP_REA = 'REG'
           AND D.CP_REA(+) IN ('final','REG','REG cash','partnership dst')
         )
         OR
         (    A.CP_REA = 'SPECIAL'
          AND D.CP_REA(+) IN ('special cash','SPECIAL')
         )
       )

「A」テーブルに対する最初の結合を完全に削除します。

3 番目と 4 番目のユニオンは似ていますが、「A」テーブルを NULL として持つ「D」テーブルからプルします。it's where 句を次の場所で変更します。

  AND A.S_I_INST(+) = 46 
  AND (
        (     A.CP_REA(+) = 'REG'
          AND D.CP_REA IN ('final','REG','REG cash','partnership dst')
        )
        OR
        (     A.CP_REA(+) = 'SPECIAL'
          AND D.CP_REA IN ('special cash','SPECIAL')
        )
      )

したがって、これは単純化された結果になるはずです

select fields
   from your "A" based query
union
select fields
   from your "D" based query

さらに、おそらくもっと単純化することもできますが、データのコンテキストをこれ以上確認しなければ、「A」テーブルと「D」テーブルの自己結合によって結合が解消される可能性がありますが、現在提示されているため不明です。

フィードバックごとに編集 オラクルのスペシャリストではありませんが、(+) は左結合構文の指標であることを認識しています...実際のサンプル テーブルとデータを試すオラクルがないため、次のわずかな調整しか提供できません。「A」が「REG」の場合、「D.CP_REA」の唯一の可能性は提供された IN リストであり、「A.CP_CREA」が「REG」になることは決してないトランザクションを扱っているようです。 「D」側には「特別な現金」または「SPECIAL」があります...逆もまた同様です。もしそうなら、多分あなたはそれに適応することができます

  AND D.S_I_INST(+) = 45 
  AND A.CP_REA IN ( 'REG', 'SPECIAL' )
  AND D.CP_REA(+) IN ( 'final','REG','REG cash','partnership dst', 
                       'special cash','SPECIAL')
于 2014-08-25T13:33:58.867 に答える