25 lines
682 B
MySQL
25 lines
682 B
MySQL
|
DELIMITER $$
|
||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getMinETD`()
|
||
|
BEGIN
|
||
|
|
||
|
/* Devuelve una tabla temporal con la primera ETD, para todos los artículos con salida hoy.
|
||
|
*
|
||
|
* @return tmp.itemMinETD(itemFk, timed)
|
||
|
*/
|
||
|
|
||
|
DECLARE vMidnight DATETIME DEFAULT util.midnight();
|
||
|
|
||
|
DROP TEMPORARY TABLE IF EXISTS tmp.itemMinETD;
|
||
|
|
||
|
CREATE TEMPORARY TABLE tmp.itemMinETD
|
||
|
(INDEX (itemFk))
|
||
|
ENGINE = MEMORY
|
||
|
SELECT s.itemFk, MIN(TIME(IFNULL(z.`hour`,vMidnight))) timed
|
||
|
FROM ticket t
|
||
|
JOIN sale s ON s.ticketFk = t.id
|
||
|
LEFT JOIN `zone` z ON z.id = t.zoneFk
|
||
|
WHERE t.shipped BETWEEN util.VN_CURDATE() AND vMidnight
|
||
|
GROUP BY s.itemFk;
|
||
|
END$$
|
||
|
DELIMITER ;
|