Professional Documents
Culture Documents
Question 1: Make A List of Project Numbers For Projects That Involve An Employee Whose Last Name Is Smith', Either As A Worker or As A Manager of The Department That Controls The Project
Question 1: Make A List of Project Numbers For Projects That Involve An Employee Whose Last Name Is Smith', Either As A Worker or As A Manager of The Department That Controls The Project
(SELECT PNUMBER
FROM PROJECT, DEPARTMENT, EMPLOYEE
WHERE DNUM=DNUMBER
AND MGRSSN=SSN AND
LNAME=‘Smith’)
UNION
FROM PROJECT, WORKS_ON, EMPLOYEE
WHERE PNUMBER=PNO AND ESSN=SSN AND LNAME=‘Smith’)
SELECT DISTINCT PNUMBER
FROM PROJECT
WHERE PNUMBER IN (SELECT PNUMBER
FROM PROJECT, DEPARTMENT, EMPLOYEE
WHERE DNUM=DNUMBER
AND MGRSSN=SSN
AND LNAME=’Smith’)
OR
PNUMBER IN (SELECT PNOFROM WORKS_ON, EMPLOYEE
WHERE ESSN=SSN AND LNAME=‘Smith’)
2. List the names of all employees with two or more dependents.
6. List the names of all employees who have a dependent with the same first
name as themselves.
SELECT LNAME, FNAME
FROM EMPLOYEE, DEPENDENT
WHERE SSN=ESSN AND FNAME=DEPENDENT_NAME;
7. Find the names of all employees who are directly supervised by ‘Franklin
Wong’.
SELECT E.LNAME, E.FNAME
FROM EMPLOYEE E, EMPLOYEE S
WHERE S.FNAME='Franklin' AND S.LNAME='Wong' AND
E.SUPERSSN=S.SSN;
8. For each project, list the project name and the total hours per week (by all
employees) spent on that project.
SELECT PNAME, SUM (HOURS)
FROM PROJECT, WORKS_ON
WHERE PNUMBER=PNO GROUP BY PNAME;
9. Retrieve the names of all employees who do not work on any project.
FROM EMPLOYEE
WHERE ESSN=SSN )
10. For each department, retrieve the department name and the average
salary of all employees working in that department.
FROM EMPLOYEE
WHERE EXISTS
LOCATION='Houston' )
( SELECT *
FROM DEPT_LOCATIONS
FROM EMPLOYEE
WHEREEXISTS
WHERE SSN=MGRSSN )
WHERE SSN=ESSN )