坚持修复此查询,我编写的两个命令出错


EMPLOYEE (fname, minit, lname, ssn, birthdate, address, sex, salary, superssn, dno)
KEY: ssn
DEPARTMENT (dname, dnumber, mgrssn, mgrstartdate)
KEY: dnumber.
PROJECT (pname, pnumber, plocation, dnum)
KEY: pnumber.
WORKS_ON (essn, pno, hours)
KEY: (essn, pno)
DEPENDENT (essn, dependent-name, sex, bdate, relationship)
KEY: (essn, dependent-name)

所以我真的很困惑如何向选择命令添加更多材料,假设添加 SSN

我想找到项目编号 47 上所有经理的姓氏和名字:

SELECT lname, fname
FROM   employee e, department d
Where d.mgrssn  = e.ssn
WHERE  e.ssn IN (SELECT w.essn
                       FROM   works_on w, project p
                       WHERE  w.pno  = p.pnumber
                                AND     w.pno ='47'
                               );

但是现在我想在其中添加ssn:

SELECT lname, fname, ssn
FROM   employee e, department d
Where d.mgrssn  = e.ssn
WHERE  ssn IN (SELECT w.essn
                       FROM   works_on w, project p
                       WHERE  w.pno  = p.pnumber
                                AND     w.pno ='02'
                               );

你能试试这个吗?

select * from employee e,works_on w,department d 
where e.ssn=d.mgrssn and e.ssn=w.essn and w.pno = 47

使用联接进行编辑

select * from employee 
join works_on on employee.ssn=works_on.essn 
join department on employee.ssn=department.mgsrssn
wher works_on.pno=47

相关内容

  • 没有找到相关文章

最新更新