Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/dev This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2019-03-29 13:17:24 +01:00
commit d70a9dee1d
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
DROP procedure IF EXISTS `vn`.`routeGuessPriority`;
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`routeGuessPriority`(IN vRuta INT)
BEGIN
/* Usa los valores del ultimo año para adivinar el orden de los tickets en la ruta
* vRuta id ruta
*/
UPDATE ticket mt
JOIN (
SELECT tt.addressFk, ROUND(IFNULL(AVG(t.priority),0),0) AS priority
FROM ticket t
JOIN ticket tt ON tt.addressFk = t.addressFk
WHERE t.shipped > TIMESTAMPADD(YEAR,-1,CURDATE())
AND tt.routeFk = vRuta
GROUP BY addressFk
) sub ON sub.addressFk = mt.addressFk
SET mt.priority = sub.priority
WHERE mt.routeFk = vRuta;
END$$
DELIMITER ;