Exercise 1 Relational Algebra

  • Upload
    lane

  • View
    57

  • Download
    1

Embed Size (px)

DESCRIPTION

Exercise 1 Relational Algebra. 6 Relations of Company. 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. - PowerPoint PPT Presentation

Citation preview

  • Exercise 1Relational AlgebraDatabase System-dww

    Database System-dww

  • Database System-dww6 Relations of Company

    Database System-dww

  • Database System-dwwExercises(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

  • Database System-dwwExercises(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.

    Database System-dww

  • (a) Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' projectGraphical approach can be used to help the logical and prosedural approachExample of above query, the graphical approach: clue from query the relations that (may) work on the query are in the red textDatabase System-dwwPProductXPname=ProductXWE> 10Hours > 10Pnumber=Pno5Dno = 5ESSN=SSNFname, Lname (?)RESULT FNAME,LNAME(DNO=5 (Rel.B))

    Database System-dww

  • List the names of employees who have a dependent with the same first name as themselves.Graphical approachDatabase System-dwwDpEDepend_name=FnameFname, Lname (?)ESSN=SSN

    Database System-dww

  • (c) Find the names of employees that are directly supervised by 'Franklin Wong'.Graphical for next questions (try by Urself)Database System-dwwE_SSN_FRANKLIN_WONG(Rel.A) ( SSN( FNAME=FRANKLIN LNAME=WONG(EMPLOYEE)))

    Database System-dww

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

    Database System-dwwTOTAL_HOURS_PROJECT (Rel.A) (PNO SUM HOURS(WORKS_ON))

    Database System-dww

  • (e) Retrieve the names of employees who work on every projectDatabase System-dwwALL_EMPLOYEE(SSN, PNO)(Rel.A) ( SSN, PNO(WORKS_ON)) ALL_PROJECT(PNO)(Rel.B) ( PNO(PROJECT)) E_ALL_PROJECT ( Rel.ARel.B) RESULT ( FNAME, LNAME (E_ALL_PROJECT * EMPLOYEE))

    Database System-dww

  • (f) Retrieve the names of employees who do not work on any projectDatabase System-dwwALL_EMPLOYEE(SSN)(Rel.A) ( SSN(EMPLOYEE)) ALL_EMPLOYEE_WORKING(SSN)(Rel.B) ( ESSN(WORKS_ON)) E_NOT_WORKING ( Rel.A - Rel.B)

    Database System-dww

  • (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 employeesDatabase System-dwwAVERAGE_SALARY_DEPARTMENT(Rel.A) (DNO AVG SALARY(EMPLOYEE)) RESULT ( DNO, AVG_SALARY(Rel.A * EMPLOYEE)) RESULT AVG SALARY( SEX=F(EMPLOYEE))

    Database System-dww

  • (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 HoustonDatabase System-dww

    Database System-dww

  • (j)List the last names of department managers who have no dependentsDatabase System-dwwD_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))

    Database System-dww