我有两个表:Item_detail(P_name,Available)和Customer_detail(P_name,Quantity)
现在我想从“可用”字段中减去“数量”字段,然后在“可用”字段中设置减去的值。我写了这段代码,但它不起作用
update Item_detail
set Available=(
select (A.Available-B.Quantity) as Available
from Item_detail as A
join (select Quantity from Customer_detail where P_name='ipod') as B
where A.P_name='ipod') ;
请帮忙!!
最佳答案
UPDATE Item_detail JOIN Customer_detail USING (P_name)
SET Item_detail.Available = Item_detail.Available - Customer_detail.Quantity
WHERE P_name='ipod'
关于java - 从不同表中减去两个字段并更新MySQL中前一个字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21476000/