简体   繁体   English

如何使用“ where子句”更新单个mysql表中的许多字段?

[英]how to update many fields in single mysql table with “where clause”?

i have table with same fields,want to update that fields,with where clause, 我有具有相同字段的表,想通过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%') ;

i tried with this,but not working, 我尝试了这个,但是没有用,

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%') ;

You can use a CASE statement in your UPDATE , so I think you want something like this: 您可以在UPDATE使用CASE语句,所以我想您需要这样的东西:

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")

See SQL Fiddle with Demo 参见带有演示的SQL Fiddle

Can you please try the below query once. 能否请您尝试以下查询一次。

UPDATE tmp_aus_inv_data
   SET `cust_region`= if(`division`= 'ROTOMOULD', 'ROTOMOULD', 'Internal') 
WHERE division in ('ROTOMOULD','EXTRUSION');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM