mysql SELECT IF 语句与 OR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9112029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 11:59:38  来源:igfitidea点击:

mysql SELECT IF statement with OR

mysqlsqlselectif-statement

提问by Robbo_UK

The following works - returns Y when chargeback equal to 1 else it defaults to N

以下工作 - 当退款等于 1 时返回 Y 否则默认为 N

IF(fd.charge_back = 1, 'Y', 'N') AS charge_back

however I cannot seem to get this one working? Is the syntax valid

但是我似乎无法让这个工作?语法是否有效

IF(compliment = ('set' OR 'Y' OR 1), 'Y', 'N') AS customer_compliment

回答by Digbyswift

Presumably this would work:

大概这会起作用:

IF(compliment = 'set' OR compliment = 'Y' OR compliment = 1, 'Y', 'N') AS customer_compliment

回答by AleXqwq

IF(compliment IN('set','Y',1), 'Y', 'N') AS customer_compliment

Will do the job as Buttle Butkussuggested.

将按照Buttle Butkus 的建议完成这项工作。