sql >> Base de Datos >  >> RDS >> Mysql

Consulta MySQL, 3 tablas, t1-t2 y luego actualice t3. ¿Cómo puedo hacer esto de la manera más eficiente?

Responde atendiendo a tu comentario a continuación:

UPDATE inventory a 
JOIN (select ProdName, sum(Quantity) Quantity from inprod group by ProdName) b on a.ProdName=b.ProdName 
JOIN (select ProdName, sum(Quantity) Quantity from outprod group by ProdName) c on a.ProdName=c.ProdName      
SET a.Quantity = c.Quantity-b.Quantity
WHERE a.ProdName='Chocolate'