CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn`.`expeditionTruck_Control_Detail` AS SELECT `e`.`truckFk` AS `id`, `e`.`eta` AS `eta`, `e`.`description` AS `destino`, `e`.`palletFk` AS `pallet`, COUNT(DISTINCT `e`.`routeFk`) AS `routes`, COUNT(DISTINCT `e`.`scanFk`) AS `scans`, COUNT(DISTINCT `e`.`expeditionTruckFk`) AS `destinos`, sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, max(`e`.`lastPacked`) AS `lastPacked` FROM `vn`.`expeditionCommon` `e` GROUP BY `e`.`truckFk`, `e`.`palletFk` ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, `e`.`eta`, `e`.`truckFk`