地狱的人,
我有一个包含条目的表,这些条目具有字段机密性(公开、机密)和字段类型(项目、海报、出版物,.)。那么,我想要做什么:我想在我选择的所有条目中筛选,但不筛选具有指定类型和机密性的条目。
例如:
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提前感谢
发布于 2012-08-16 07:51:30
从您的示例中,您希望选择confidentiality不保密的记录。对吗?尝尝这个,
SELECT ....
FROM ....
WHERE type <> 'project' AND confidentiality <> 'confidential'或者是和
SELECT ....
FROM ....
WHERE NOT (type = 'project' AND confidentiality = 'confidential')发布于 2012-08-16 07:51:28
考虑到您提供的信息,您的查询看起来还不错。
这种较短的查询有效吗?
SELECT ...
WHERE (type = 'project' AND confidentiality = 'public')
OR type <> 'project'注:上述查询可缩短为:
SELECT ...
WHERE confidentiality = 'public'
OR type <> 'project'发布于 2012-08-16 07:51:45
你的逻辑似乎是:
SELECT ... WHERE type != 'project' OR confidentiality = 'public';https://stackoverflow.com/questions/11982663
复制相似问题