salix/db/routines/vn/views/routesControl.sql

28 lines
811 B
MySQL
Raw Permalink Normal View History

2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`routesControl`
AS SELECT `t`.`routeFk` AS `routeFk`,
COUNT(`e`.`id`) AS `expeditions`,
COUNT(`es`.`id`) AS `scanned`,
COUNT(DISTINCT `es`.`palletFk`) AS `pallets`,
max(`es`.`scanned`) AS `lastScanned`,
max(`rs`.`description`) AS `description`,
max(`rs`.`eta`) AS `eta`
FROM (
(
(
(
`vn`.`ticket` `t`
JOIN `vn`.`expedition` `e` ON(`t`.`id` = `e`.`ticketFk`)
)
LEFT JOIN `vn`.`expeditionScan` `es` ON(`es`.`expeditionFk` = `e`.`id`)
)
LEFT JOIN `vn`.`expeditionPallet` `ep` ON(`ep`.`id` = `es`.`palletFk`)
)
LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `ep`.`truckFk`)
)
WHERE `t`.`shipped` >= `util`.`VN_CURDATE`()
AND `t`.`routeFk` <> 0
GROUP BY `t`.`routeFk`
ORDER BY max(`rs`.`eta`)