我有一个 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'))