28 lines
817 B
MySQL
28 lines
817 B
MySQL
|
CREATE OR REPLACE DEFINER=`root`@`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(`et`.`description`) AS `description`,
|
||
|
max(`et`.`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`.`expeditionTruck` `et` ON(`et`.`id` = `ep`.`truckFk`)
|
||
|
)
|
||
|
WHERE `t`.`shipped` >= `util`.`VN_CURDATE`()
|
||
|
AND `t`.`routeFk` <> 0
|
||
|
GROUP BY `t`.`routeFk`
|
||
|
ORDER BY max(`et`.`eta`)
|