0

大家好,

我有一个包含条目的表,这些条目具有字段机密性(公共、机密)和字段类型(项目、海报、出版物……)。那么我想做什么:我想在我的 SELECT 中过滤所有条目,但不过滤具有指定类型和机密性的条目。

例如:

type=project, confidentiality=public       | should be selected
type=project, confidentiality=confidential | should be not selected
type=poster, confidentiality=public        | should be selected
type=poster, confidentiality=confidential  | should be selected

有没有好的方法来做到这一点?

SELECT ...
WHERE (type = 'project' AND confidentiality = 'public') OR type = 'publication' OR type
= 'poster' OR type = 'lecture' OR type = 'committee'
GROUP BY

提前致谢

4

3 回答 3

1

鉴于您提供的信息,您的查询看起来不错。

这个较短的查询会起作用吗?

SELECT ...
WHERE (type = 'project' AND confidentiality = 'public')
OR type <> 'project'

注意:上面的查询可以简写为:

SELECT ...
WHERE confidentiality = 'public'
OR type <> 'project'
于 2012-08-16T07:51:28.993 回答
1

从您的示例中,您要选择confidentiality机密的记录。对?试试这个,

SELECT ....
FROM ....
WHERE type <> 'project' AND confidentiality <> 'confidential'

OR 与

SELECT ....
FROM ....
WHERE NOT (type = 'project' AND confidentiality = 'confidential')
于 2012-08-16T07:51:30.340 回答
0

您的预期逻辑似乎是:

SELECT ... WHERE type != 'project' OR confidentiality = 'public';
于 2012-08-16T07:51:45.810 回答