简体   繁体   English

T-SQL 与逻辑

[英]T-SQL AND logic

I have table TABLE1 with columns A, B and C.我有包含 A、B 和 C 列的表 TABLE1。 I need to get all rows from the table where columns A, B and C are not all equal to 1, eg,我需要从表中获取所有行,其中列 A、B 和 C 不都等于 1,例如,

WHERE NOT (A = 1 AND B = 1 AND C = 1)

This works.这行得通。 However, I need to do this in a fashion that only uses AND and OR statements.但是,我需要以仅使用 AND 和 OR 语句的方式执行此操作。 I had expected this to work:我原以为这会起作用:

WHERE A != 1 
  AND B != 1 
  AND C != 1 

However, this only returns rows where no row = 1, ie, too few rows.但是,这仅返回没有行 = 1 的行,即行太少。

Using MS SQL 2008.使用 MS SQL 2008。

WHERE (A <> 1 OR B <> 1  OR C <> 1)

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

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