hr_org,包含以下列: -
Org id Spoc Name
123 HR A
123 IT A
123 VP A
67 IT B
78 HR C
78 IT C
我想创建一个查询,其中只有那些只定义了IT Spoc的名称。
例如: -
select name
from hr_org
where SPOC ='IT'
会给A和B. 但是对于另一个spoc(HR和VP)也被藐视了。我的输出应该只是取B。
答案 0 :(得分:1)
select name
from hr_org
where SPOC ='IT' and name not in (select name from hr_org where SPOC<>'IT')
答案 1 :(得分:0)
select *
from hr_org h1
where spoc='IT'
and not exists (
select 1
from hr_org h2
where h2.spoc <> h1.spoc
and h2.name = h1.name
)