DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getVolume`() BEGIN /** * Cálculo de volumen en líneas de compra * @table tmp.buy(buyFk) */ SELECT t.name Temp, CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * item_getVolume(b.itemFk, b.packagingFk)) / vc.trolleyM3 / 1000000 ,1) AS DECIMAL(10,2)) carros , CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * item_getVolume(b.itemFk, b.packagingFk)) / vc.palletM3 / 1000000,1) AS DECIMAL(10,2)) espais FROM buy b JOIN tmp.buy tb ON tb.buyFk = b.id JOIN volumeConfig vc JOIN item i ON i.id = b.itemFk JOIN itemType it ON it.id = i.typeFk LEFT JOIN temperature t ON t.code = it.temperatureFk GROUP BY Temp; END$$ DELIMITER ;