如何从查询中排除某些值[SQL]
如标题所述,如何从查询中排除某些值[SQL],sql,aggregate-functions,having-clause,nested-queries,Sql,Aggregate Functions,Having Clause,Nested Queries,如标题所述,NotPrimID,可以有两个不同的值示例1和示例2 "ExampleTable" NotPrimID Text 0 "Example 1" 0 "Example 1" 0 "Example 2" 1 "Example 1" 1 "Example
NotPrimID
,可以有两个不同的值示例1
和示例2
"ExampleTable"
NotPrimID Text
0 "Example 1"
0 "Example 1"
0 "Example 2"
1 "Example 1"
1 "Example 1"
2 "Example 1"
2 "Example 2"
IF:IFNotPrimID
具有这两个值,则应自动将其从查询结果中排除
我想要的:查询,它将删除所有的NotPrimID
,结果只有“示例1”,但是如果NotPrimID
也有“示例2”作为可能的结果,它应该被自动排除
问题:如何排除某些
NotPrimID
,如果它确实有附加值?您可以使用分组依据
和拥有
:
select notprimid
from exampletable
group by notprimid
having min(text) = max(text) and min(text) = 'Example1'
这将返回所有只有一个不同的
文本的notprimid
,其值必须是'Example1'
非常有效-谢谢!