需求
更新表中的N個字段的值
1、根據A表字段的值,更新B表字段的值
2、根據條件更新字段的值
方法
更新多個字段
-- 方法一
update a set a.province=(select province from b where b.mobile=a.mobile);
update a set a.city=(select city from b where b.mobile=a.mobile);
-- 方法二
update a set a.province=b.province,a.city=b.city from a,b where a.mobile=b.mobile;
update a set a.province=b.province,a.city=b.city from a inner join b on a.mobile=b.mobile;
-- 方法三
update a inner join b on a.mobile=b.mobile set a.province=b.province,a.city=b.city;
-- 方法四(最優)
update a set(a.province,a.city)=(select province,city from b where b.mobile=a.mobile);
根據條件更新字段
update t_cure_plan a
set (inject) =
(select case
when inject = '第一針' then
'1'
when inject = '第二針' then
'2'
else
inject
end as newInject
from t_cure_plan b
where a.id = b.id);