2016-07-28 104 views
0

Hello and Good Morning。MySQL使用計算的第二個表更新第一個表格

我有2個表,它看起來像這樣。

Table: receiving

enter image description here

Table: purchorder

enter image description here

,這裏是我的問題。

我如何使用列QtyPackpurchorder其中列RInumber = RINoQtyStan更新列ReflectedQty

請,請注意該列purchorder會/ 100

這裏QtyStan是我所需要的輸出。

enter image description here

TYSM爲今後幫助

回答

1

試試這個:

update receiving r 
join purchorder p 
on r.RInumber = p.RINo 
set r.ReflectedQty = r.ReflectedQty - p.QtyStan - (p.QtyStan/100) 
-- where r.RINumber = 'myvalue' 

我編輯的代碼

update receiving r 
join purchorder p 
on P.RInumber = r.RINo 
set p.ReflectedQty = Format(p.ReflectedQty - r.QtyPack - (r.QtyStan/100),2) where RINumber = 'RI861RMA' 
+0

先生,我想使用標準像'那裏RINumber = 'myvalue的' ' –

+0

@NyxAssasin添加'where where子句將罰款,檢查我的答案agai請。 – Blank

+0

我會試試這個主席先生等着:) –