2024-01-30 08:45:37 +00:00
|
|
|
DELIMITER $$
|
2024-02-01 12:02:03 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`intrastat_estimateNet`(vIntrastat INT, vUnidades INT)
|
2024-01-30 08:45:37 +00:00
|
|
|
RETURNS double
|
|
|
|
DETERMINISTIC
|
|
|
|
BEGIN
|
|
|
|
|
2024-02-01 12:02:03 +00:00
|
|
|
DECLARE vNet DOUBLE;
|
2024-01-30 08:45:37 +00:00
|
|
|
|
2024-02-01 12:02:03 +00:00
|
|
|
SELECT ROUND(vUnidades / (SUM(media) / COUNT(media)), 2) INTO vNet
|
|
|
|
FROM (SELECT *, unidades / neto media
|
|
|
|
FROM vn2008.intrastat_data
|
|
|
|
WHERE intrastat_id = vIntrastat
|
|
|
|
AND neto
|
|
|
|
AND unidades > 0
|
|
|
|
ORDER BY odbc_date DESC
|
|
|
|
LIMIT 20) t;
|
|
|
|
|
|
|
|
RETURN vNet/2;
|
2024-01-30 08:45:37 +00:00
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|