SELECT item_id, warehouse_id, SUM(amount) amount FROM basket_item GROUP BY warehouse_id CALL bionic_from_type (#type); SELECT t.item_id, t.available, t.price, a.Foto, a.Article, a.Categoria, a.Medida, a.Tallos, a.Color, o.Abreviatura FROM vn2008.t_bionic_item t JOIN vn2008.Articles a ON a.Id_Article = t.item_id LEFT JOIN vn2008.Origen o ON a.id_origen = o.id WHERE t.available > 0 ORDER BY a.Article, a.Medida LIMIT 400; CALL bionic_from_item (#item); SELECT p.warehouse_id, p.grouping, p.price, p.rate, t.amount, l.available - IFNULL(t.amount, 0) available FROM vn2008.t_bionic_lot l JOIN vn2008.t_bionic_price p ON p.warehouse_id = l.warehouse_id LEFT JOIN ( SELECT warehouse_id, SUM(amount) amount FROM basket_item WHERE item_id = #item GROUP BY warehouse_id ) t ON t.warehouse_id = l.warehouse_id ORDER BY warehouse_id, grouping;