繁体   English   中英

从表WHERE`column` = x中选择*如果`column`!= -1

[英]Select * from table WHERE `column` = x if `column` != -1

我需要做出选择,

Select * from table WHERE column = x if column != -1

但我暂时不知道。

任何人都知道或做过这样的事吗?

谢谢。

你也应该这样写

Select * from table 
WHERE 
1 = case when column != -1 then 
        case when column = x then 1 else 0 end
    else 1 end

您可以在where子句中使用大小写。 同样,您可以添加更多条件条件,例如,

Select * from table 
WHERE 
1 = case when column != -1 then 
        case when column = x then 1 else 0 end
    else 1 end
AND 
1 = case when column1 [conditional operator] value then
        case when column1 = xx then 1 else 0 end
    else 1 end

这只是一个示例,您可以将更多的条件条件整合在一起,即使您可以在其他部分添加更多的情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM