【发布时间】:2015-11-30 17:00:48
【问题描述】:
Employee(fname, minit, lname, SSN, bdate, address, sex, salary, superssn, dno); fname,minit,lname is the employee's name; bdate is birth date; superssn is supervisor's social security #; dno is dept #
Department(dname, DNUMBER, mgrssn, mgrstartdate); mgrssn is manager ssn
Dept_locations(DNUMBER, DLOCATION); dlocation is department location
Project(Pname, PNUMBER, plocation, dnum)
Works_on(ESSN, PNO, hours); ESSN is employee ssn, pno is project number
Dependent(ESSN, DEPENDENT_NAME, sex, bdate, relationship)
我想列出所有不在项目 7 工作且位于底特律的经理的姓氏和名字、SSN
这看起来不错:
Select e.ssn, e.lname, e.fname
from employee e, department d
where (d.mgrssn = e.ssn)
where e.ssn NOT in (
select w.essn
from works_on w
where w.pno = '07'
and p.plocation = 'Detroit'
)
我想我需要在 pno = 07 之前放置一个 pno =works_on 联合声明,但有人告诉我我不需要它。所以我现在真的很困惑。
我还需要在括号中包含 where (d.mgrssn = e.ssn) 吗?
【问题讨论】:
-
您不想要底特律的经理,还是想要底特律的经理?因为你不在排除底特律从事项目 7 的所有经理。
-
我不想要底特律的经理。你能写一个答案吗,我会接受的
标签: sql database jointable nested-queries notin