Consulta SQL
Bom dia, eu gostaria de saber se alguem de vcs sabe como otimizar esse sql, pois a tabela de Pesquisa (T_PSQ) tem 12.000 registros e a dos Itens de Consumo da Pesquisa (T_MPCNS) tem 3.100.000 registros aproximadamente e eu preciso gerar um total no campo valor (VLR_TOT) da tabela de Itens de Consumo agrupado pela Regiao (T_REG) da pessoa referente a pesquisa, aí meu SQL ficou da seguinte forma:
[b:eec5d288a6]select B.CD_REG, R.DS_REG, sum(VLR_TOT)
from T_PSQ P join T_BRR B on (B.CD_BRR = P.CD_BRR)
join T_REG R on (R.CD_REG = B.CD_REG)
join T_MPCNS C on (C.CD_PSQ = P.CD_PSQ)
where VLR_TOT > 0
and (FLG1_NAOSB = ´S´ or FLG1_NAOSB is NULL) and (FLG_NAOSB = ´S´ or FLG1_NAOSB is NULL)
group by B.CD_REG, R.DS_REG[/b:eec5d288a6]
Ps. Esse sql já esta funcionando corretamente, eu gostaria de saber se alguem sabe alguma forma de otimizá-lo
[b:eec5d288a6]select B.CD_REG, R.DS_REG, sum(VLR_TOT)
from T_PSQ P join T_BRR B on (B.CD_BRR = P.CD_BRR)
join T_REG R on (R.CD_REG = B.CD_REG)
join T_MPCNS C on (C.CD_PSQ = P.CD_PSQ)
where VLR_TOT > 0
and (FLG1_NAOSB = ´S´ or FLG1_NAOSB is NULL) and (FLG_NAOSB = ´S´ or FLG1_NAOSB is NULL)
group by B.CD_REG, R.DS_REG[/b:eec5d288a6]
Ps. Esse sql já esta funcionando corretamente, eu gostaria de saber se alguem sabe alguma forma de otimizá-lo
Zero
Curtidas 0