salix/db/routines/vn/procedures/raidUpdate.sql

32 lines
990 B
MySQL
Raw Normal View History

2024-03-05 11:41:54 +00:00
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`raidUpdate`()
BEGIN
2024-04-12 05:58:18 +00:00
/**
* Actualiza el travel de las entradas de redadas
*/
2024-03-05 11:41:54 +00:00
UPDATE entry e
JOIN entryVirtual ev ON ev.entryFk = e.id
JOIN travel t ON t.id = e.travelFk
JOIN (
SELECT *
FROM (
SELECT id, landed, tt.warehouseInFk, tt.warehouseOutFk
FROM travel t
JOIN (
SELECT t.warehouseInFk, t.warehouseOutFk
FROM entryVirtual ev
JOIN entry e ON e.id = ev.entryFk
JOIN travel t ON t.id = e.travelFk
GROUP BY t.warehouseInFk, t.warehouseOutFk
) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk
WHERE shipped > util.VN_CURDATE() AND isDelivered = FALSE
ORDER BY t.landed
LIMIT 10000000000000000000
) t
GROUP BY warehouseInFk, warehouseOutFk
) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk
SET e.travelFk = t.id;
END$$
DELIMITER ;