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

时间:2015-11-28 19:37:49

标签: sql database select in-clause

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)

所以我真的很困惑如何在select命令中添加更多材料,让我们说添加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'
                               );

1 个答案:

答案 0 :(得分:0)

你可以尝试一下吗?

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