40 lines
889 B
SQL
40 lines
889 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`makePCSGraf`(vDated DATE)
|
|
BEGIN
|
|
|
|
|
|
DECLARE vHour INT DEFAULT 0;
|
|
DECLARE vMinute INT DEFAULT 0;
|
|
DECLARE vBoxes INT;
|
|
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS vn.pcsDay;
|
|
CREATE TEMPORARY TABLE vn.pcsDay
|
|
SELECT 0 as hh, 0 as mm, 0 as boxes;
|
|
|
|
-- Creamos una tabla soporte para acumular las cajas a lo largo del dia
|
|
WHILE vHour < 24 DO
|
|
|
|
WHILE vMinute < 59 DO
|
|
|
|
SET vMinute = vMinute + 1;
|
|
|
|
INSERT INTO vn.pcsDay(hh,mm) VALUES(vHour, vMinute);
|
|
|
|
END WHILE;
|
|
|
|
SET vMinute = -1;
|
|
SET vHour = vHour + 1;
|
|
|
|
END WHILE;
|
|
|
|
-- Acumulamos
|
|
UPDATE vn.pcsDay pd
|
|
LEFT JOIN (SELECT * FROM vn.pcs_graf WHERE dia = vDated) pg USING(hh,mm)
|
|
SET pd.boxes = pd.boxes + pg.box;
|
|
|
|
SELECT * FROM vn.pcsDay;
|
|
|
|
END$$
|
|
DELIMITER ;
|