[英]using nested case condition in mysql query
if(qtype==3)
column=somecolumn;
else if(qtype==2)
{
if(open==0)
column=anycolumn;
else
column =somecolumn;
}
else{
acolumn,bcolumn,ccolumn //this else----|
} |
----------------|
I want to achieve the above nested if-else condition in my mysql query.where the condition will be based on one of the column.this is what i have done so far. 我想在我的mysql查询中实现上述嵌套的if-else条件。其中条件将基于column之一。这是我到目前为止所做的。
select qtype,open,(Case when qtype=2 then answer
Else (Case when qtype=3 then
(Case when open=0 then somecolumn
Else othercolumn End) End)
Else....//how to implement this else here)
i am in confusion how to integrate the last else part? 我很困惑如何整合最后的其他部分?
Thanks 谢谢
The format is correct, but you switch the 2 and 3 compared to the if-else psuedocode at the begining: 格式正确,但是与开头的if-else伪代码相比,您将2和3进行了切换:
select qtype,open,(Case when qtype=3 then answer
Else (Case when qtype=2 then
(Case when open=0 then somecolumn
Else othercolumn End) End))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.