是否可以在MySQL中使用IF(cond1 AND cond2,result,else result)? [英] Is it possible to use IF(cond1 AND cond2,result,else result) in MySQL?

查看:233
本文介绍了是否可以在MySQL中使用IF(cond1 AND cond2,result,else result)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果连续5列的值为0,我想进行更新查询。我的第一个想法是:

I want to do update query if the consecutive 5 column have 0 value. My first idea is:

UPDATE `table_name` 
SET `count` = IF(`col1`=0.00 AND 
                 `col2`=0.00 AND 
                 `col3`=0.00 AND 
                 `col4`=0.00 AND 
                 `col5`=0.00,  count+1, count)

但我认为在IF条件下使用AND不起作用。任何想法?谢谢

But I think using AND in IF condition isn't work. Any idea? Thanks before

推荐答案

中使用 AND IF 完全有效,但正如Grijesh所说,使用 WHERE 子句中的条件是通常的方法。

Using AND in an IF is perfectly valid, but as Grijesh suggets, using the condition in the WHERE clause is the usual way to do it.

您的查询不应该出现任何错误。

Your query though shouldn't give any errors.

这篇关于是否可以在MySQL中使用IF(cond1 AND cond2,result,else result)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆