DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`travelVolume_get`(vFromDated DATE, vToDated DATE, vWarehouseFk INT) BEGIN SELECT tr.landed Fecha, a.name Agencia, count(DISTINCT e.id) numEntradas, FLOOR(sum(item_getVolume(b.itemFk, b.packagingFk) * b.stickers / 1000000 )) AS m3 FROM vn.travel tr JOIN vn.agencyMode a ON a.id = tr.agencyModeFk JOIN vn.entry e ON e.travelFk = tr.id JOIN vn.buy b ON b.entryFk = e.id WHERE tr.landed BETWEEN vFromDated AND vToDated AND e.isRaid = FALSE AND tr.warehouseInFk = vWarehouseFk GROUP BY tr.landed , a.name ; END$$ DELIMITER ;