Download presentation
1
Exercise 2 Relational Calculus
Database System-dww
2
6 Relations of Company Database System-dww
3
FNAME,LNAME(SALARY>‘50000’ (EMPLOYEES))
Find the first and last names of all employees whose salary is above $50,000 Rel Algebra FNAME,LNAME(SALARY>‘50000’ (EMPLOYEES)) Tuple Rel Calculus {t.FNAME,t.LNAME|EMPLOYEE(x) AND t.SALARY>‘50000’)) Domain Rel Calculus {ac|(Ǝi) EMPLOYEE(abcdefghijkl) AND i>‘50000’)) SQL select FNAME, LNAME from EMPLOYEES where SALARY>‘50000’ Database System-dww
4
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'. (e) Retrieve the names of employees who work on every project. Database System-dww
5
Exercises (f) Retrieve the names of employees who do not work on any project. (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. (j)List the last names of department managers who have no dependents. Database System-dww
6
P W E WORKS_ON_ProductX (Rel.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 P Pnumber=Pno W ESSN=SSN E Fname, Lname (?) Pname=‘ProductX’ Hours > 10 Dno = 5 ProductX > 10 5 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)) Database System-dww
7
P W E { e.LNAME, e.FNAME | EMPLOYEE(e) AND e.DNO=5 AND (Ǝp)(Ǝw)
Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' project P Pnumber=Pno W ESSN=SSN E Fname, Lname (?) Pname=‘ProductX’ Hours > 10 Dno = 5 ProductX > 10 5 { e.LNAME, e.FNAME | EMPLOYEE(e) AND e.DNO=5 AND (Ǝp)(Ǝw) (WORKS_ON(w) AND PROJECT(p) AND e.SSN=w.ESSN AND w.PNO=p.PNUMBER AND p.PNAME='ProductX' AND w.HOURS>10 ) } { qs | EMPLOYEE(qrstuvwxyz) AND z=5 AND (Ǝa) (Ǝb) (Ǝe) (Ǝf) (Ǝg) ( WORKS_ON(efg) AND PROJECT(abcd) AND t=e AND f=b AND a='ProductX' AND g>10 ) } Database System-dww
8
List the names of employees who have a dependent with the same first name as themselves.
Dp Depend_name=Fname E Fname, Lname (?) ESSN=SSN RESULT FNAME,LNAME(DEPENDENT (ESSN,DEPEND_NAME)=(SSN,FNAME)(EMPLOYEE)) { e.LNAME, e.FNAME | EMPLOYEE(e) AND (Ǝd) ( DEPENDENT(d) AND e.SSN=d.ESSN AND e.FNAME=d.DEPENDENT_NAME ) } { qs | (Ǝt) (Ǝa) (Ǝb) ( EMPLOYEE(qrstuvwxyz) AND DEPENDENT(abcde) AND a=t AND b=q ) } Database System-dww
9
Find the names of employees that are directly supervised by 'Franklin Wong'.
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)) { e.LNAME, e.FNAME | EMPLOYEE(e) AND (Ǝs) ( EMPLOYEE(s) AND s.FNAME='Franklin' AND s.LNAME='Wong' AND e.SUPERSSN=s.SSN ) } { qs | (Ǝy) (Ǝa) (Ǝc) (Ǝd) ( EMPLOYEE(qrstuvwxyz) AND EMPLOYEE(abcdefghij) AND a='Franklin' AND c='Wong' AND y=d ) } Database System-dww
10
Retrieve the names of employees who work on every project
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)) { e.LNAME, e.FNAME | EMPLOYEE(e) AND (Ѵp) ( NOT(PROJECT(p)) OR (Ǝw) (WORKS_ON(w) AND p.PNUMBER=w.PNO AND w.ESSN=e.SSN ) ) } { qs | (Ǝt) ( EMPLOYEE(qrstuvwxyz) AND (Ѵb) ( NOT(PROJECT(abcd)) OR (Ǝe) (Ǝf) (WORKS_ON(efg) AND e=t AND f=b) ) } Database System-dww
11
Retrieve the names of employees who do not work on any project
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)) { e.LNAME, e.FNAME | EMPLOYEE(e) AND NOT(Ǝw) ( WORKS_ON(w) AND w.ESSN=e.SSN ) } { qs | (Ǝt) ( EMPLOYEE(qrstuvwxyz) AND NOT(Ǝa) (WORKS_ON(abc) AND a=t ))} Database System-dww
12
{ e.LNAME, e.FNAME, e.ADDRESS | EMPLOYEE(e) AND (Ǝp) (Ǝw)
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 { e.LNAME, e.FNAME, e.ADDRESS | EMPLOYEE(e) AND (Ǝp) (Ǝw) (WORKS_ON(w) AND PROJECT(p) AND e.SSN=w.ESSN AND w.PNO=p.PNUMBER AND p.PLOCATION='Houston' AND NOT(Ǝl) ( DEPT_LOCATIONS(l) AND e.DNO=l.DNUMBER AND l.DLOCATION='Houston' ) ) } { qsv | (Ǝt) (Ǝz) ( EMPLOYEE(qrstuvwxyz) AND (Ǝb) (Ǝc) (Ǝe) (Ǝf) ( WORKS_ON(efg) AND PROJECT(abcd) AND t=e AND f=b AND c='Houston' AND NOT(Ǝh) NOT(Ǝi) ( DEPT_LOCATIONS(hi) AND z=h AND i='Houston’ ) ) } Database System-dww
13
List the last names of department managers who have no dependents
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)) { e.LNAME | EMPLOYEE(e) AND (Ǝd) ( DEPARTMENT(d) AND e.SSN=d.MGRSSN AND NOT(Ǝx) (DEPENDENT(x) AND e.SSN=x.ESSN) ) } { s | (Ǝt) ( EMPLOYEE(qrstuvwxyz) AND (Ǝc) ( DEPARTMENT(abcd) AND t=c AND NOT(Ǝe) (DEPENDENT(efghi) AND e=t) ) } Database System-dww
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.