MySQL:如果确定值,则更新列

编程入门 行业动态 更新时间:2024-10-27 23:20:44
本文介绍了MySQL:如果确定值,则更新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不是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:如果确定值,则更新列

本文发布于:2023-10-20 09:15:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1510556.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:则更   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!