作者cutekid (可爱小孩子)
看板Database
标题Re: [SQL ]update A from B 多重条件
时间Wed Nov 29 00:27:20 2017
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'
: 的资料,请问该怎麽写比较好呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.168.31.46
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Database/M.1511886443.A.50D.html
※ 编辑: cutekid (1.168.31.46), 11/29/2017 00:41:15
1F:推 redskyism: 感谢~~ 11/29 00:47