我在下面有这个问题,但它花了3个小时才能运行...你知道我怎么能优化这个查询以获得更好的性能?
SELECT *
FROM stg.F_STG_ORCAMENTO F_STG_ORCAMENTO
WHERE 1=1
AND F_STG_ORCAMENTO.COD_CONTA LIKE '6%'
AND F_STG_ORCAMENTO.COD_CONTA NOT IN (SELECT DISTINCT F_STGT_CNT_EXPLOR_CTB_GERAL.C_CNT_GERAL
FROM STG.F_STGT_CNT_EXPLOR_CTB_GERAL F_STGT_CNT_EXPLOR_CTB_GERAL
WHERE F_STGT_CNT_EXPLOR_CTB_GERAL.C_LOLOJA=F_STG_ORCAMENTO.C_CENT_CUSTO
AND INPUT(substr(put(F_STGT_CNT_EXPLOR_CTB_GERAL.DTA_CNT_EXPLOR,8.),1,4),4.)=F_STG_ORCAMENTO.DTA_ANO
AND INPUT(substr(put(F_STGT_CNT_EXPLOR_CTB_GERAL.DTA_CNT_EXPLOR,8.),5,2),2.)=F_STG_ORCAMENTO.DTA_MES
AND F_STGT_CNT_EXPLOR_CTB_GERAL.C_CNT_GERAL=F_STG_ORCAMENTO.COD_CONTA)
AND F_STG_ORCAMENTO.V_NUM_CUSTOS > 0
UNION ALL
SELECT *
FROM stg.F_STG_ORCAMENTO F_STG_ORCAMENTO
WHERE 1=1
AND F_STG_ORCAMENTO.COD_CONTA LIKE '94%'
AND F_STG_ORCAMENTO.COD_CONTA NOT IN (SELECT DISTINCT SUBSTR(F_STGT_CNT_EXPLOR_CTB_GERAL.C_CNT_ANL,4,9)
FROM STG.F_STGT_CNT_EXPLOR_CTB_GERAL F_STGT_CNT_EXPLOR_CTB_GERAL
WHERE F_STG_ORCAMENTO.C_CENT_CUSTO=F_STGT_CNT_EXPLOR_CTB_GERAL.C_LOLOJA
AND F_STG_ORCAMENTO.DTA_ANO=INPUT(substr(put(F_STGT_CNT_EXPLOR_CTB_GERAL.DTA_CNT_EXPLOR,8.),1,4),4.)
AND F_STG_ORCAMENTO.DTA_MES=INPUT(substr(put(F_STGT_CNT_EXPLOR_CTB_GERAL.DTA_CNT_EXPLOR,8.),5,2),2.)
AND SUBSTR(F_STGT_CNT_EXPLOR_CTB_GERAL.C_CNT_ANL,4,9)=F_STG_ORCAMENTO.COD_CONTA)
AND F_STG_ORCAMENTO.V_NUM_CUSTOS > 0
感谢。