我不是SQL专家,快速的Google搜索并不能给我带来太多好处(尽管我认为我没有使用最好的搜索词组).希望你们能给我一些指导.
I'm not an SQL expert and a quick google search hasn't gotten me much (though I don't think I'm using the best search phrases). Hope you guys can give me some guidance.
我在存储数字的表中有一列.我希望仅将此数字设置为2(如果以前等于1).我想知道是否有可能避免这种情况:
I have a certain column in a table that stores a number. I want this number to be set to 2 ONLY if it previously equaled 1. I was wondering if it was possible to avoid this:
$val = mysql_fetch_row(mysql_query("SELECT columnA FROM tableName WHERE something = '$someValue')); if($val[0] == 1) { .....UPDATE tableName SET columnA = 2....... }是否可以直接查询数据库?像这样:SET columnA = 2 if columnA = 1
Is it possible to directly query the database? With something like this: SET columnA = 2 if columnA = 1
推荐答案实际上,您要查找的查询应该是:
Actually the query you're looking for should be:
update tableName set columnA = 2 where columnA = 1您提到的"if"实际上是一个条件.这些条件是在update语句的where子句中设置的.
The "if" you're mentioning is actually a condition. And these conditions are set in the where clause of the update statement.
就这样:)
更多推荐
MySQL:如果确定值,则更新列
发布评论