SQL 具有多个条件和连接条件的 Where 子句

SQL Where Clause with multiple and joined conditions

在下面的 table 中,我想写一个 SQL 查询来排除 col1=2col2=1 时的行。只有当两个条件都满足时,我才想删除该列。如果 col1=2col2<>1 那么我想保留该行。

col1 col2
1 2
1 2
2 2
2 1

我正在尝试下面的代码片段,但它不起作用:

select *
from table
where (col1<>2 and col2<>1)

您应该使用 or 而不是 and

您可以使用:

WHERE NOT (col1 <> 2 AND col2 <> 1)

WHERE (col1 <> 2 OR col2 <> 1)