26 lines
636 B
SQL
26 lines
636 B
SQL
CREATE OR REPLACE DEFINER=`vn`@`localhost`
|
|
SQL SECURITY DEFINER
|
|
VIEW `vn`.`lastHourProduction`
|
|
AS SELECT `t`.`warehouseFk` AS `warehouseFk`,
|
|
cast(
|
|
sum(
|
|
IFNULL(
|
|
`p`.`volume`,
|
|
`p`.`width` * `p`.`height` * `p`.`depth`
|
|
) / 1000000
|
|
) AS decimal(5, 1)
|
|
) AS `m3`
|
|
FROM (
|
|
(
|
|
(
|
|
`vn`.`warehouse` `w`
|
|
JOIN `vn`.`ticket` `t` ON(`t`.`warehouseFk` = `w`.`id`)
|
|
)
|
|
LEFT JOIN `vn`.`expedition` `e` ON(`t`.`id` = `e`.`ticketFk`)
|
|
)
|
|
LEFT JOIN `vn`.`packaging` `p` ON(`p`.`id` = `e`.`packagingFk`)
|
|
)
|
|
WHERE `e`.`created` BETWEEN `util`.`VN_NOW`() - INTERVAL 1 HOUR
|
|
AND `util`.`VN_NOW`()
|
|
GROUP BY `t`.`warehouseFk`
|