[英]mysql if condition is met
I am using MySQL (phpmyadmin) for my database.我的数据库使用 MySQL (phpmyadmin)。 I want to change the value in a field depending on another's field info.
我想根据另一个字段信息更改字段中的值。
My table would be "info" and my column1 store_number
, column2 store_name
and column3 state
, so if in field store_name
there is a character string like Store number 3
, then change column1 value to 3
.我的表将是 "info" 和我的 column1
store_number
、 column2 store_name
和 column3 state
,所以如果在字段store_name
有一个像Store number 3
这样的字符串,那么将 column1 值更改为3
。
I tried我试过
UPDATE info
IF store_name LIKE "%store number 3 %"
SET store_number = '3'
WHERE state LIKE "%california%"
I want to change the store number in all stores in california depending in the store name.我想根据商店名称更改加利福尼亚州所有商店的商店编号。
You were on the right track with your WHERE
clause already.您已经在使用
WHERE
子句的正确轨道上。 You could move your conditional logic to be part of it to get:您可以将条件逻辑移动到其中以获得:
UPDATE info
SET store_number='3'
WHERE state LIKE '%california%' AND
store_name LIKE '%store number 3%'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.