23 lines
671 B
MySQL
23 lines
671 B
MySQL
|
DELIMITER $$
|
||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`preOrdenarRuta`(IN vRutaId INT)
|
||
|
BEGIN
|
||
|
/* Usa los valores del ultimo año para adivinar el orden de los tickets en la ruta
|
||
|
* vRutaId id ruta
|
||
|
* DEPRECATED use vn.routeGressPriority
|
||
|
*/
|
||
|
|
||
|
UPDATE Tickets mt
|
||
|
JOIN (
|
||
|
SELECT tt.Id_Consigna, round(ifnull(avg(t.Prioridad),0),0) as Prioridad
|
||
|
from Tickets t
|
||
|
JOIN Tickets tt on tt.Id_Consigna = t.Id_Consigna
|
||
|
where t.Fecha > TIMESTAMPADD(YEAR,-1,util.VN_CURDATE())
|
||
|
AND tt.Id_Ruta = vRutaId
|
||
|
GROUP BY Id_Consigna
|
||
|
) sub ON sub.Id_Consigna = mt.Id_Consigna
|
||
|
SET mt.Prioridad = sub.Prioridad
|
||
|
WHERE mt.Id_Ruta = vRutaId;
|
||
|
|
||
|
END$$
|
||
|
DELIMITER ;
|