CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn`.`workerSpeedExpedition` AS SELECT `sv`.`ticketFk` AS `ticketFk`, sum(`sv`.`litros`) AS `litros`, sum( IF( `sub`.`started` > `util`.`VN_NOW`() + INTERVAL -1 HOUR, `sv`.`litros`, 0 ) ) AS `literLastHour`, cast( 60 * sum(`sv`.`litros`) / time_to_sec( timediff(max(`sub`.`finished`), min(`sub`.`started`)) ) AS decimal(10, 1) ) AS `litersByMinute`, `sub`.`code` AS `workerCode`, `sub`.`cajas` AS `cajas`, `sub`.`warehouseFk` AS `warehouseFk` FROM ( `vn`.`saleVolume` `sv` JOIN `vn`.`expeditionTimeExpended` `sub` ON(`sub`.`ticketFk` = `sv`.`ticketFk`) ) GROUP BY `sub`.`code`