繁体   English   中英

如何在 SQL Server 中两列的 where 子句中组合条件

[英]How do I combine conditions in where clause for two columns in SQL Server

我有一个简单的表numInfo有两个整数列,比如col1col2 现在我想将它们与一个数字进行比较,所以我会写一个这样的查询:

select * from numInfo where col1 < 26 OR col2 <26

是否可以将两个条件组合为:

select * from numInfo where (col1 or col2) < 26

上面的查询给了我一个错误,所以我只想知道如何将条件组合成一个?

不可能在简洁的表达式中组合<的条件。

如果是= ,则可以使用in 对于<>您可以使用not in <没有相应的快捷方式。 您甚至不能使用least() / greatest() ,因为 SQL Server 不支持这些功能。

你需要:

select * from numInfo where (col1 < 26 or col2 < 26);

暂无
暂无

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

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