更新專欄中,我有兩個表:甲骨文:根據列從另一個表
列A是上,我們將採取加盟的列。我需要更新,如:
B = if(D not null) then D
else C
我嘗試這樣做:
update Tab1 x
set B = case when
(select D from Tab2 t2
inner join Tab1 t1
on t1.A = t2.A
where t1.A = x.A) is not null
then (select D from Tab2 t2
inner join Tab1 t1
on t1.A = t2.A
where t1.A = x.A)
else x.D END
where x.A > (user_input) and x.A <= (user_input)
這給了我輸出:0行更新。
另外,作爲一個說明,我需要在一個更新語句本身做到這一點。表Tab1中還有其他非依賴列可在此更新中更新。
我知道這看起來很亂,而且兩次執行相同的select子查詢並不是最優化的,但我並不真正瞭解如何實現這一點。
任何幫助或指針表示讚賞!