[英]MySQL : Select all the rows except those having the specified values in columns
I have data in my table that looks like the following. 我的表中的数据如下所示。
dcno | etype | debit | credit |
------+-------+-------+--------+
1 | sale | 1200 | 1000 |
2 | sale | 1000 | 600 |
3 | sale | 1100 | 9001 |
1 | purc | 1274 | 1281 |
4 | sale | 1119 | 2811 |
6 | sale | 2345 | 233 |
2 | purc | 4467 | 121 |
3 | sale | 8885 | 1214 |
What I want is a query that doesnt consider the row having the specified dcno
and etype
. 我想要的是一个不考虑具有指定
dcno
和etype
的行的查询。 For example if I specify that I don't want the row having the dcno of 1 and etype of sale it should return the following: 例如,如果我指定不希望dcno为1且etype为sale的行,则应返回以下内容:
dcno | etype | debit | credit |
------+-------+-------+--------+
2 | sale | 1000 | 600 |
3 | sale | 1100 | 9001 |
1 | purc | 1274 | 1281 |
4 | sale | 1119 | 2811 |
6 | sale | 2345 | 233 |
2 | purc | 4467 | 121 |
3 | sale | 8885 | 1214 |
I have tried with the following 我尝试了以下
SELECT *
FROM pledger
WHERE dcno <> 1 AND pledger.etype <> 'sale'
but that didn't work (as expected). 但这没用(按预期)。 Can anyone please tell me how may I achieve this?
谁能告诉我我该如何实现?
You want or
: 您想要
or
:
SELECT *
FROM pledger
WHERE dcno <> 1 OR pledger.etype <> 'sale'
Boolean logic says that NOT (X AND Y)
is logically equivalent to NOT X OR NOT Y
. 布尔逻辑表示
NOT (X AND Y)
在逻辑上等效于NOT X OR NOT Y
So, NOT (dcno = 1 AND etype = 'sale')
is dcno <> 1 OR etype <> 'sale'
. 因此,
NOT (dcno = 1 AND etype = 'sale')
是dcno <> 1 OR etype <> 'sale'
。 Note: this doesn't take NULL
into account, but that is not relevant here. 注意:这并未考虑
NULL
,但这与此处无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.