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

26 lines
681 B
MySQL
Raw Normal View History

2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`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`