2024-07-22 09:52:42 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:10:46 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`facturacion_media_anual_update`()
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
TRUNCATE TABLE bs.clientAnnualConsumption;
|
|
|
|
|
|
|
|
REPLACE bi.facturacion_media_anual(Id_Cliente, Consumo)
|
|
|
|
SELECT clientFk, avg(Facturacion)
|
|
|
|
FROM (
|
|
|
|
SELECT clientFk, YEAR(issued) year, MONTH(issued) month, sum(amount) as Facturacion
|
|
|
|
FROM vn.invoiceOut
|
|
|
|
WHERE issued BETWEEN TIMESTAMPADD(YEAR,-1,util.VN_CURDATE()) AND TIMESTAMPADD(DAY, - DAY(util.VN_CURDATE()),util.VN_CURDATE())
|
|
|
|
GROUP BY clientFk, year, month
|
|
|
|
) vol
|
|
|
|
GROUP BY clientFk;
|
2024-07-22 09:52:42 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|