[英]SQL how to filter out a specific row with conflicting where clause
这应该是一个简单的问题,但是由于某种原因我无法使其正常工作。 我有一个如下表:
|Name|Attribute|
----------------
|Foo | 1 |
|Foo | 2 |
|Foo | 3 |
|Bar | 1 |
|Bar | 2 |
|Bar | 3 |
|Yum | 1 |
|Yum | 2 |
|Yum | 3 |
我想像下面这样过滤它
|Name|Attribute|
----------------
|Foo | 2 |
|Foo | 3 |
|Bar | 1 |
|Bar | 2 |
|Bar | 3 |
请注意,仅当Attribute = 1时,我才删除了所有“ Yum”并删除了“ Foo”
问题是当我做这样的事情时
SELECT *
FROM table
WHERE name in ('Foo', 'Bar')
AND (name != 'Foo' AND attribute != 1)
我得到这个结果
|Name|Attribute|
----------------
|Bar | 2 |
|Bar | 3 |
我会以为方括号将事物组合在一起?
我认为在or
:
where (name = 'Bar') or (name = 'Foo' and attribute <> 1)
Select
*
From
table
Where
(Name <> 'Yum') and
not (Name = 'Foo' and attribute = 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.