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

28 lines
783 B
SQL

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`saleVolume_Today_VNH`
AS SELECT `t`.`nickname` AS `Cliente`,
`p`.`name` AS `Provincia`,
`c`.`name` AS `Pais`,
cast(sum(`sv`.`volume`) AS decimal(5, 1)) AS `volume`
FROM (
(
(
(
(
`vn`.`saleVolume` `sv`
JOIN `vn`.`ticket` `t` ON(`t`.`id` = `sv`.`ticketFk`)
)
JOIN `vn`.`address` `a` ON(`a`.`id` = `t`.`addressFk`)
)
JOIN `vn`.`province` `p` ON(`p`.`id` = `a`.`provinceFk`)
)
JOIN `vn`.`country` `c` ON(`c`.`id` = `p`.`countryFk`)
)
JOIN `vn`.`warehouse` `w` ON(`w`.`id` = `t`.`warehouseFk`)
)
WHERE `w`.`name` = 'VNH'
AND `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `util`.`dayend`(`util`.`VN_CURDATE`())
GROUP BY `t`.`nickname`,
`p`.`name`