refs #6444 create vn.intrastat_estimateNet.sql

This commit is contained in:
Ivan Mas 2024-01-30 09:45:37 +01:00
parent 89a5f3dff8
commit ed0f942a57
1 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,19 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`intrastat_estimateNet`(intINSTRASTAT INTEGER,intUNIDADES INTEGER)
RETURNS double
DETERMINISTIC
BEGIN
DECLARE n DOUBLE;
SELECT ROUND(intUNIDADES / (SUM(MEDIA) / COUNT(media)), 2) INTO n FROM
(SELECT *, unidades / neto MEDIA
FROM vn2008.intrastat_data
WHERE intrastat_id = intINSTRASTAT AND neto
AND unidades > 0
ORDER BY odbc_date DESC
LIMIT 20) t;
RETURN n/2;
END$$
DELIMITER ;