Stuck on fixing this query, mistakes in two commands that I wrote

爱⌒轻易说出口 提交于 2019-12-12 04:41:48

问题


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)

So I'm just really confused by how do I add more materials to the select command, let's say add SSN

I want to find the last name and first name of all the managers who is on project number 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'
                               );

But now I want add ssn to it:

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:


Could you try this?

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

edit using joins

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


来源:https://stackoverflow.com/questions/33975601/stuck-on-fixing-this-query-mistakes-in-two-commands-that-i-wrote

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!