Código SQL:
Ver original
( SELECT tdaVta, CASE encargopralVta WHEN 'S' THEN '1' WHEN 'N' THEN '2' END AS encargoPral , COUNT(*) AS numven, SUM(impnetoVta) AS impnet, SUM(impdtoVta) AS impdto, avg(impnetoVta) AS avgnet, avg(impdtoVta) AS avgdto FROM encargos WHERE YEAR(fechaVta) BETWEEN '$limany1' AND '$limany2' AND anuladaVta <>'S' AND promocionVta=$limpro1 AND impnetoVta > 0 GROUP BY tdaVta, encargopral ORDER BY tdaVta, encargopral ) UNION ALL ( SELECT tdaVta, '3' AS encargopral, COUNT(*) AS numven, SUM(impnetoVta) AS impnet, SUM(impdtoVta) AS impdto, avg(impnetoVta) AS avgnet, avg(impdtoVta) AS avgdto FROM encargos WHERE YEAR(fechaVta) BETWEEN '$limany1' AND '$limany2' AND anuladaVta <>'S' AND promocionVta =$limpro1 AND impnetoVta=0 GROUP BY tdaVta, encargopral ORDER BY tdaVta, encargopral ) ORDER BY tdaVta, encargopral
funciona correctamente pero tarda 45 segundos en ejecutarse.
la tabla encargos tiene definidos los indices
Código SQL:
Ver original
PRIMARY KEY (`clienteVta`, `numVta`), UNIQUE INDEX `encarrec` (`tdaVta`, `encargoVta`), INDEX `fechamontageTaller` (`fechamontageTaller`), INDEX `fechapedidoTaller_horapedidoTaller` (`fechapedidoTaller`, `horapedidoTaller`), INDEX `fechaVta` (`fechaVta`), INDEX `monturaVta` (`monturaVta`), INDEX `Pareja` (`tdaVta`, `parejaVta`), INDEX `vendedorVta` (`vendedorVta`)
creo que si genero un indice en la tabla ganaria rendimiento pero no se como hacer que la busqueda sea por ese indice.