问题
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