0% found this document useful (0 votes)
236 views8 pages

Question 6.16 Page 186: ( ( ( Employee) ) - X - ( ( Works - On) ) - X - ( ( Project) ) )

The document contains a series of SQL queries with varying levels of complexity. The queries retrieve employee, department, project and other related data from database tables to answer questions about: employees who work more than 10 hours on a specific project; employees who have dependents with the same first name; employees directly supervised by a specific manager; total hours spent on each project; employees who work on every project; employees who do not work on any project; average salary by department; average salary of female employees; employees who work on projects in a specific location but are not in departments in that location; and department managers without dependents.

Uploaded by

Aayush Manubansh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
236 views8 pages

Question 6.16 Page 186: ( ( ( Employee) ) - X - ( ( Works - On) ) - X - ( ( Project) ) )

The document contains a series of SQL queries with varying levels of complexity. The queries retrieve employee, department, project and other related data from database tables to answer questions about: employees who work more than 10 hours on a specific project; employees who have dependents with the same first name; employees directly supervised by a specific manager; total hours spent on each project; employees who work on every project; employees who do not work on any project; average salary by department; average salary of female employees; employees who work on projects in a specific location but are not in departments in that location; and department managers without dependents.

Uploaded by

Aayush Manubansh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

Question 6.

16 page 186

a. Retrieve the names of all employees in department 5 who work more than 10 hours per week on the 'ProductX' project.
Fname, Minit,,Lname,{[Fname,Lname, SSN ( Dno = 5 Employee)] |X|ssn=essn [Essn,Pno ( Hours > 10 Works_on)] |X|pno = pnumber [Pnumber ( Pname = ‘Product ‘X’ Project)]}

select fname, lname


from employee, works_on, project
where pname='ProductX'
and hours>10
and dno=5
and pno=pnumber
and essn=ssn;

fname lname

John Smith
Joyce English

========================

b. List the names of all employees who have a dependent with the same first name as themselves.
Fname,Minit, Lname,[(Fname, Minit,,Lname, SSN Employee) |X|ssn=essn, fname = dependent_name ( Dependent_name, essn Dependent)]

select fname, lname


from employee, dependent
where fname=dependent_name
and essn=ssn;

fname lname

1
========================

c. Find the names of all employees who are directly supervised by ‘Franklin Wong’.
Fname,Minit, Lname{(Fname,Lname, Mgrssn Employee E1) |X|E1.Mgrssn = E2.ssn [ SSN( Fname = ‘Franklin’. Lname = ‘Wong’ Employee E2)]}

select fname, lname


from employee
where superssn in
(select ssn
from employee
where fname='Franklin'
and lname='Wong');

OR

select E1.fname, E1.lname


from employee E1, employee E2
where E2.fname='Franklin'
and E2.lname='Wong'
and E1.superssn= E2.ssn;

fname lname

John Smith
Ramesh Narayan
Joyce English

========================

2
d. For each project, list the project name and the total hours per week (by all employees) spent on that project.

 Pnumber, Pname{[Pnumber, Pname Project)] |X|Pnumber = Pno (pnosum hours Works_on)]}

select pname, sum (hours)


from works_on, project
where pno=pnumber
group by pname;

pname (sum)

Newbenefits 55.0
Computerization 55.0
ProductX 52.5
ProductY 37.5
Reorganization 25.0
ProductZ 50.0

e. Retrieve the names of all employees who work on every project.

 Fname, Minit, Lname {[Fname, Minit, Lname, SSN Employee)] |X|SSN = Essn [ (Pno, ESSN Works_on) ÷ (Pnumber Project)]}

select fname, lname


from employee
where not exists
((select pnumber from project)
minus
(select pno from works_on where ssn=essn));

SELECT LNAME, FNAME


FROM EMPLOYEE
WHERE NOT EXISTS
(SELECT * FROM WORKS_ON B
WHERE (B.PNO IN
(SELECT PNUMBER
FROM PROJECT))
AND NOT EXISTS
(SELECT * FROM WORKS_ON C
WHERE C.ESSN = SSN
AND C.PNO = B.PNO));
-----------------
Test SQL statement with dunm = 4

select fname, lname


from employee
3
where not exists
((select pnumber from project where dnum = 4)
minus
(select pno from works_on where ssn=essn));

FNAME LNAME
--------------- ---------------
Alicia Zeleya
Ahmad Jabbar

f. Retrieve the names of all employees who do not work on any project.

 Fname, Minit, Lname {[Fname, Minit, Lname, SSN Employee)] |X|SSN =SSN [ (SSN Employee) - (ESSN Works_on)]}

select fname, lname


from employee
where not exists (select *
from employee, works_on
where essn=ssn);

OR:

select fname, lname


from employee
where ssn not in (select essn
from works_on);

fname lname

========================

4
g. For each department, retrieve the department name and the average salary of all employees working in that department.
 Dname, Avg_salary {[Dnumber, Dname Department)] |X|Dnumber = Dno (dno avg salary Employee)]}

select dname, avg(salary)


from employee, department
where dnumber=dno
group by dname;

dname (avg)

Headquaters 55000.00
Administration 31000.00
Research 33250.00

5
h. Retrieve the average salary of all female employees.

 avg salary ( Sex = ‘F’ Employee)

select avg(salary)
from employee
where sex='F';

(avg)

31000.00

========================

6
i. Find the names and addresses of all employees who work on at least one project located in Houston but whose department has no location in Houston.
T1  {Fname, Minit,,Lname, ssn {[Fname, Minit,,Lname, SSN, dno (Employee)] |X|Dno = Dnumber {[[dno (Employee)] - Dnumber ( Dlocation = ‘Houston’ Dept_locations)] }}
T2  ESSN{[ ESSN, Pno (Works_on)] |X|Pno = Pnumber [Pnumber ( Plocation = ‘Houston’ Project)]}

 Fname, Minit, Lname (T1 |X|SSN =SSN T2 ) }

select fname, lname, address


from employee, works_on
where ssn=essn
and works_on.pno in
(select pnumber from project where plocation='Houston')
and employee.dno not in
(select dnumber from dept_locations where dlocation='Houston');

fname lname address

Jennifer Wallace 291 Berry, Bellaire, TX

7
j. List the last names of all department managers who have no dependents.

 Fname, Minit, Lname {[Fname, Minit, Lname, SSN Employee)] |X|SSN =MRRSSN [(MGRSSN Department) - (ESSN Dependent)]}

SQL> select fname, lname


2 from employee, department
3 where ssn = mgrssn
4 and mgrssn not in
5 (select essn from dependent);

FNAME LNAME
--------------- ---------------
James Borg

========================

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy