Exercise 1 Relational Algebra Database System-dww.
-
Upload
carol-griffith -
Category
Documents
-
view
317 -
download
3
Transcript of Exercise 1 Relational Algebra Database System-dww.
Exercise 1Relational Algebra
Database System-dww
Database System-dww
6 Relations of Company
Database System-dww
Exercises
(a) Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' project.(b) List the names of employees who have a dependent with the same first name as themselves.(c) Find the names of employees that are directly supervised by 'Franklin Wong'. (d) For each project, list the project name and the total hours per week (by all employees) spent on that project.(e) Retrieve the names of employees who work on every project.
Database System-dww
Exercises(f) Retrieve the names of employees who do not work on any project.(g) For each department, retrieve the department name, and the average salary of
employees working in that department.(h) Retrieve the average salary of all female employees.(i) Find the names and addresses of employees who work on at least one project located in Houston but whose department has no location in Houston.List the last names of department managers who have no dependents.
(a) Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' project
Graphical approach can be used to help the logical and prosedural approach
Example of above query, the graphical approach: clue from query the relations that (may) work on the query are in the red text
Database System-dww
P
ProductX
Pname=‘ProductX’
W E
> 10
Hours > 10
Pnumber=Pno
5
Dno = 5
ESSN=SSN Fname, Lname (?)
WORKS_ON_ProductX (Rel.A) (PNAME=‘ProductX’(PROJECT) PNUMBER=PNO(WORKS_ON))
EMPLOYEE_DEPT5_WORKS_MORE_10_onProductX (Rel.B) ((EMPLOYEE) SSN=ESSN(HOURS>10(Rel.A)))
RESULT FNAME,LNAME(DNO=‘5’ (Rel.B))
List the names of employees who have a dependent with the same first name as themselves.
Graphical approach
Database System-dww
Dp EDepend_name=Fname Fname, Lname (?)
ESSN=SSN
RESULT FNAME,LNAME(DEPENDENT (ESSN,DEPEND_NAME)=(SSN,FNAME)(EMPLOYEE))
(c) Find the names of employees that are directly supervised by 'Franklin Wong'.
Graphical for next questions (try by Urself)
Database System-dww
E_SSN_FRANKLIN_WONG(Rel.A) (SSN(FNAME=‘FRANKLIN’ LNAME=‘WONG’(EMPLOYEE)))
E_SUPERVISED_BY_FRANKLIN_WONG (Result) (FNAME, LNAMES(EMPLOYEE) SUPERSSN=SSN(Rel.A))
(d) For each project, list the project name and the total hours per week (by all employees) spent on that project
Using function
Database System-dww
TOTAL_HOURS_PROJECT (Rel.A)
(PNOℱSUM HOURS(WORKS_ON))
RESULT (PNAME, TOT_HOURS(Rel.A) PNO=PNUMBER(PROJECT))
(e) Retrieve the names of employees who work on every project
Database System-dww
ALL_EMPLOYEE(SSN, PNO)(Rel.A) (SSN, PNO(WORKS_ON))
ALL_PROJECT(PNO)(Rel.B) (PNO(PROJECT))
E_ALL_PROJECT (Rel.A÷Rel.B)
RESULT (FNAME, LNAME (E_ALL_PROJECT * EMPLOYEE))
(f) Retrieve the names of employees who do not work on any project
Database System-dww
ALL_EMPLOYEE(SSN)(Rel.A) (SSN(EMPLOYEE))
ALL_EMPLOYEE_WORKING(SSN)(Rel.B) (ESSN(WORKS_ON))
E_NOT_WORKING (Rel.A - Rel.B)
RESULT (FNAME, LNAME ((EMPLOYEE) SSN=ESSN(E_NOT_WORKING))
(g) For each department, retrieve the department name, and the average salary of employees working in that department
(h) Retrieve the average salary of all female employees
Database System-dww
AVERAGE_SALARY_DEPARTMENT(Rel.A)
(DNOℱAVG SALARY(EMPLOYEE))
RESULT (DNO, AVG_SALARY(Rel.A * EMPLOYEE))
RESULT
ℱAVG SALARY(SEX=‘F’(EMPLOYEE))
(i) Find the names and addresses of employees who work on at least one project located in Houston but whose department has no location in Houston
Database System-dww
E_WORK_PROJ_IN_HOUSTON(Rel.A) (ESSN(WORKS_ON) PNO=PNUMBER(PLOCATION=‘HOUSTON’(PROJECT)))
E_D_NOT_IN_HOUSTON(Rel.B) (SSN(EMPLOYEE) DNO=DNUMBER(DLOCATION≠‘HOUSTON’(DEPARTMENT_LOCATIONS)))
RESULT (FNAME, LNAME, ADDRESS((EMPLOYEE) (Rel.A-Rel.B))
(j)List the last names of department managers who have no dependents
Database System-dww
D_MNG_SSN(Rel.A)(SSN(DEPARTMENT)
E_WITH_DEPENDENT(Rel.A)(SSN(DPENDENT)
MNGR_NO_DEPENDENT(Rel.A – Rel.B)
RESULT(LNAME(EMPLOYEE * MNGR_NO_DEPENDENT))