salix/db/versions/11124-greenBamboo/01-firstScript.sql

19 lines
600 B
MySQL
Raw Permalink Normal View History

2024-08-20 09:43:08 +00:00
-- Calculamos todos los volumenes de todos los tickets una sola vez
2024-09-10 10:58:16 +00:00
/* Se ejecutará el dia de test - master manualmente para no hacer lenta la subida
2024-08-20 09:45:50 +00:00
CREATE OR REPLACE TEMPORARY TABLE tmp.tTicketVolume
2024-08-20 09:43:08 +00:00
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT t.id, SUM(s.quantity * ic.cm3delivery / 1000000) volume
2024-08-20 09:44:38 +00:00
FROM vn.sale s
JOIN vn.ticket t ON t.id = s.ticketFk
JOIN vn.itemCost ic ON ic.itemFk = s.itemFk
2024-08-20 09:43:08 +00:00
AND ic.warehouseFk = t.warehouseFk
GROUP BY t.id;
2024-08-20 09:44:38 +00:00
UPDATE vn.ticket t
2024-08-20 10:01:28 +00:00
JOIN tmp.tTicketVolume tv ON tv.id = t.id
2024-08-20 09:43:08 +00:00
SET t.volume = tv.volume;
2024-08-20 09:45:50 +00:00
DROP TEMPORARY TABLE tmp.tTicketVolume;
2024-09-10 10:58:16 +00:00
*/