关于连接的SQL语句

关于连接的SQL语句,sql,oracle,join,Sql,Oracle,Join,问题:对于与其主管不住在同一城市的所有员工,请将员工姓名列为“员工”,并将主管姓名列为“主管” 关系: Staff (Snum, Name, DOB, Address, City, Gender, Salary, Supervisor,Dnum) Dept ( Dnum, Dname, Manager, Mgrstartdate ) Deptlocation ( Dnum, Dcity ) Project ( Pnum, Pname, Pcity, Dnum ) Workson ( Sn

问题:对于与其主管不住在同一城市的所有员工,请将员工姓名列为“员工”,并将主管姓名列为“主管”

关系:

Staff (Snum, Name, DOB, Address, City, Gender, Salary, Supervisor,Dnum) 
Dept ( Dnum, Dname, Manager, Mgrstartdate ) 
Deptlocation ( Dnum, Dcity ) 
Project ( Pnum, Pname, Pcity, Dnum ) 
Workson ( Snum, Pnum, Hours )

Column Supervisor of table Staff is a foreign key which references column Snum of table Staff.
Column Dnum of table Staff is a foreign key which references column Dnum of table Dept.
Column Manager of table Dept is a foreign key which references column Snum of table Staff.
Column Dnum of table Deptlocation is a foreign key which references column Dnum of table Dept.
Column Dnum of table Project is a foreign key which references column Dnum of table Dept.
Column Snum of table Workson is a foreign key which references column Snum of table Staff.
Column Pnum of table Workson is a foreign key which references column Pnum of table Project.
到目前为止,我得到的是:

SELECT name AS staff_member,  supervisor
from staff s
INNER JOIN deptlocation d ON s.dnum = d.dnum
WHERE s.city NOT EXISTS (d.city)
我做错了什么

Error:Your query has syntax errors.
Description:java.sql.SQLException: ORA-00920: invalid relational operator

试试这个:

SELECT name AS staff_member,  supervisor
from staff s
INNER JOIN deptlocation d ON s.dnum = d.dnum
WHERE NOT EXISTS (
select 1 from deptlocation aa
aa.city=s.city 
)

您需要一个
自联接
。 我认为
staff
表中的
supervisor
列指向
staff
表中
supervisor
snum

Select st.name as staff_member, 
       Sp.name as supervisor
  From staff st 
       Inner join staff sp 
       On (st.supervisor = sp.snum)
 Where st.city <> sp.city;
选择st.name作为职员,
Sp.作为主管的姓名
从staff街
内部连接工作人员sp
开启(st.supervisor=sp.snum)
其中圣城sp.city;

干杯

哪一列表示某人居住的城市?样本数据最好用+。请将您的问题包括在内,您当前的尝试和您想要的结果。关于更多细节,我想在员工专栏《城市更新你的问题》中说,添加一个清晰的数据样本和预期结果,请通过编辑而不是评论来澄清。请阅读您正在使用的功能的文档/手册。