Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 仅从表中获取一项的查询_Sql_Sql Server_Plsql_Plsqldeveloper - Fatal编程技术网

Sql 仅从表中获取一项的查询

Sql 仅从表中获取一项的查询,sql,sql-server,plsql,plsqldeveloper,Sql,Sql Server,Plsql,Plsqldeveloper,包含以下列的人力资源组织:- 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 但另一方面,发言人和副总裁也遭到了挑战。我的输出应该只获取B。

包含以下列的人力资源组织:-

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 但另一方面,发言人和副总裁也遭到了挑战。我的输出应该只获取B。

为什么它获取B?您的规则是什么,将B定义为要获取的3个选项中正确的一个?
select name 
from hr_org
where SPOC ='IT' and name not in (select name from hr_org where SPOC<>'IT')
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
)