Re: [SQL ]update A from B 多重條件

作者: cutekid (可愛小孩子)   2017-11-29 00:27:20
update t1
set A1 = case when t1.A2 = t2.B2 then t2.B1
else t3.B1
end
from A t1
left join B t2 on t1.A2 = t2.B2
left join B t3 on t3.B2 = 'ALL'
where t1.A2 = t2.B2 or t3.B2 = 'ALL'
※ 引述《redskyism (dreamer)》之銘言:
: 資料庫名稱:MSQL
: 資料庫版本:
: 內容/問題描述:
: 請教SQL
: update A set A.A1 = B.B1 from A inner join B on A.A2 = B.B2
: 想在B2 中增加"All"的資料,若資料有A2對應不到B2時則找 B2='All'
: 的資料,請問該怎麼寫比較好呢?
作者: redskyism (dreamer)   2017-11-29 00:47:00
感謝~~

Links booklink

Contact Us: admin [ a t ] ucptt.com