Optimizar tiempo de respuesta (Ayuda)
Publicado por Eick Alonso (1 intervención) el 31/10/2014 01:29:17
Hola que tal tengo un problema, al momento de consultar una base de datos, quiero saber si esta bien estructurado mi Query se los agradeceria mucho si me pueden apoyar gracias!!
Select FUN.Linea, FUN.Num_Parte, (Select max(Prog.tipo_movto) from tbfun_movimientosfundicion
Prog WHERE Prog.Status = 'A' And Prog.Fechaafect = FUN.Fecha AND Prog.Num_Parte = FUN.NUm_parte And Prog.Linea = FUN.Linea AND Prog.Status = FUN.status) as tipo_movto, fun.CvePrograma, FUN.Fecha, (Select SUM(Prog.Cantidad) from tbFUN_movimientosfundicion Prog WHERE Prog.Status = 'A' And prog.Fechaafect = FUN.Fecha AND Prog.Num_Parte = FUN.NUm_parte And Prog.Linea = FUN.Linea and Prog.Status = FUN.status ) as Canreal,SUM(FUN.Cantidad) AS CanProg from tbFUN_progproduccion FUN WHERE FUN.Status = 'A' And FUN.Fecha between '2014/10/01' And
'2014/10/29' GROUP BY FUN.Linea, FUN.Num_Parte, FUN.Fecha, FUN.Status, fun.cveprograma union Select FUN.Linea, FUN.Num_Parte, FUN.Tipo_Movto, (Select Prog.CvePrograma from tbFUN_ProgProduccion Prog WHERE Prog.Status = 'A' And Prog.Fecha = FUN.FechaAfect AND Prog.Num_Parte = FUN.NUm_parte And Prog.Linea = FUN.Linea AND Prog.Status = FUN.status) as CvePrograma, FUN.FechaAfect, SUM(FUN.Cantidad) AS CanReal, (Select SUM(Prog.Cantidad) from tbFUN_ProgProduccion Prog WHERE Prog.Status = 'A' And Prog.Fecha = FUN.FechaAfect AND Prog.Num_Parte = FUN.NUm_parte And Prog.Linea = FUN.Linea and Prog.Status = FUN.status ) as CanProgra from tbFUN_MovimientosFUNDICION FUN WHERE FUN.Status = 'A' And FUN.FechaAfect between '2014/10/01' And '2014/10/29' AND FUN.Tipo_Movto in ('203','205','253') GROUP BY
FUN.Linea, FUN.Num_Parte, FUN.Tipo_Movto, FUN.FechaAfect, FUN.Status
Select FUN.Linea, FUN.Num_Parte, (Select max(Prog.tipo_movto) from tbfun_movimientosfundicion
Prog WHERE Prog.Status = 'A' And Prog.Fechaafect = FUN.Fecha AND Prog.Num_Parte = FUN.NUm_parte And Prog.Linea = FUN.Linea AND Prog.Status = FUN.status) as tipo_movto, fun.CvePrograma, FUN.Fecha, (Select SUM(Prog.Cantidad) from tbFUN_movimientosfundicion Prog WHERE Prog.Status = 'A' And prog.Fechaafect = FUN.Fecha AND Prog.Num_Parte = FUN.NUm_parte And Prog.Linea = FUN.Linea and Prog.Status = FUN.status ) as Canreal,SUM(FUN.Cantidad) AS CanProg from tbFUN_progproduccion FUN WHERE FUN.Status = 'A' And FUN.Fecha between '2014/10/01' And
'2014/10/29' GROUP BY FUN.Linea, FUN.Num_Parte, FUN.Fecha, FUN.Status, fun.cveprograma union Select FUN.Linea, FUN.Num_Parte, FUN.Tipo_Movto, (Select Prog.CvePrograma from tbFUN_ProgProduccion Prog WHERE Prog.Status = 'A' And Prog.Fecha = FUN.FechaAfect AND Prog.Num_Parte = FUN.NUm_parte And Prog.Linea = FUN.Linea AND Prog.Status = FUN.status) as CvePrograma, FUN.FechaAfect, SUM(FUN.Cantidad) AS CanReal, (Select SUM(Prog.Cantidad) from tbFUN_ProgProduccion Prog WHERE Prog.Status = 'A' And Prog.Fecha = FUN.FechaAfect AND Prog.Num_Parte = FUN.NUm_parte And Prog.Linea = FUN.Linea and Prog.Status = FUN.status ) as CanProgra from tbFUN_MovimientosFUNDICION FUN WHERE FUN.Status = 'A' And FUN.FechaAfect between '2014/10/01' And '2014/10/29' AND FUN.Tipo_Movto in ('203','205','253') GROUP BY
FUN.Linea, FUN.Num_Parte, FUN.Tipo_Movto, FUN.FechaAfect, FUN.Status
Valora esta pregunta


0