简体   繁体   English

MySQL使用其他表中的信息更新字段

[英]MySQL update a field using info in other table

How can I make an update of this tables?: 如何更新这些表?:

Products table 产品

  • IdProd [PK] IdProd [PK]
  • Description 描述
  • Cost 成本

Transactions table 交易

  • IdTransaction [PK] IdTransaction [PK]
  • IdProd [FK] IdProd [FK]
  • Quantity 数量
  • Total

I want to update the Total quantity finding the Cost in the products table, and multiplying it to my Quantity in my transactions table, but I don't really know how can I do this.. 我想更新在产品表中找到成本的总数量,并将其乘以我的交易表中的数量,但我真的不知道我该怎么做...

Use Update from JOIN syntax 使用JOIN语法Update

update Transactions A
INNER JOIN Products B
ON A.IdProd = B.IdProd
set A.Total = A.Quantity * B.cost

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM