我有相同字段的表,想要使用where子句更新那些字段,
update tmp_aus_inv_data
SET cust_region= "ROTOMOULD"
WHERE division = "ROTOMOULD" ;
update tmp_aus_inv_data
SET cust_region= "Internal"
WHERE division = "EXTRUSION" and ucase(cust_region) like ucase('Internal%') ;
我试过这个,但没有工作,
update tmp_aus_inv_data
(set cust_region= "ROTOMOULD"),
(SET cust_region= "Internal")
WHERE division = "ROTOMOULD" and WHERE division = "EXTRUSION" and ucase(cust_region) like ucase('Internal%') ;
答案 0 :(得分:3)
您可以在CASE
中使用UPDATE
语句,因此我认为您需要这样的内容:
update tmp_aus_inv_data
SET cust_region
= case
when division = "ROTOMOULD" then "ROTOMOULD"
when division = "EXTRUSION"
and ucase(cust_region) like ucase('Internal%')
then "Internal"
else cust_region
end
where division in ("ROTOMOULD", "EXTRUSION")
答案 1 :(得分:1)
您能否请一次尝试以下查询。
UPDATE tmp_aus_inv_data
SET `cust_region`= if(`division`= 'ROTOMOULD', 'ROTOMOULD', 'Internal')
WHERE division in ('ROTOMOULD','EXTRUSION');