[英]Select * from table WHERE `column` = x if `column` != -1
I need to make a select like, 我需要做出选择,
Select * from table WHERE column = x if column != -1
but i have no idea for now. 但我暂时不知道。
Anyone know or made in past something like that? 任何人都知道或做过这样的事吗?
Thanks. 谢谢。
You should also write like this, 你也应该这样写
Select * from table
WHERE
1 = case when column != -1 then
case when column = x then 1 else 0 end
else 1 end
You can utilize case when in where clause. 您可以在where子句中使用大小写。 Similarly you can add more conditional criteria like,
同样,您可以添加更多条件条件,例如,
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
This is just an example how you can integrate more conditional criteria together, even though you can add more case when in else part even. 这只是一个示例,您可以将更多的条件条件整合在一起,即使您可以在其他部分添加更多的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.