Exercise 1 Relational Algebra Database System-dww.

Slides:



Advertisements
Similar presentations
Exercise 2 Relational Calculus
Advertisements

The Relational Algebra
The Relational Calculus
Database System - Assignment #3 Sept. 2012Yangjun Chen ACS Assignment #3 due Wed., Nov. 14, (30) Exercise 7.17 on Page 235 Show the result.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-1 Query Processing and.
COMPANY schema EMPLOYEE
Lecture 1 Relational Algebra and Relational Calculus.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 (Continued) The Relational Algebra and Calculus.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Chapter 6 Additional Relational Operations Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Basic Queries. 2 Retrieval Queries in SQL SQL has one basic statement for retrieving information from a database; the SELECT statement This is not the.
SQL Query Slides Sharif University Of Technology Database Systems CE 384 Prepared By: Babak Bagheri Hariri
Your Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Instructor: Mr. Ahmed Al Astal Chapter 8 (Cont.) SQL-99: Schema Definition,
Displaying Data from Multiple Tables. EMPNO DEPTNO LOC NEW YORK CHICAGO NEW YORK DALLAS
Dept. of Computer & Information Sciences
FEN More about SELECT, Nested selects GROUP BY, HAVING, ORDER BY Other joins Aggregate functions Views More about SQL.
Company Database. CREATE TABLE DEPARMENT ( DNAME VARCHAR(10) NOT NULL, DNUMBER INTEGER NOT NULL, MGRSSN CHAR(9), MGRSTARTDATE CHAR(9), PRIMARY KEY (DNUMBER),
LAB 4 FIGURES.
Data Warehousing/Mining 1 Data Warehousing/Mining Comp 150 Aggregation in SQL (not in book) Instructor: Dan Hebert.
Employee database: Conceptual Schema in ERD Chapter 3, page 62.
SQL SQL (Structured Query Language) is used to define, query, and modify relational databases Every relational database system understands SQL SQL is standard:
Review Database Application Development Access Database Development ER-diagram Forms Reports Queries.
Chapter 19 Query Processing and Optimization
Relational Algebra. Manipulating Databases To access information in a database we use a query Ex: How many customers have the first name = `John’? Good.
More SQL: Complex Queries, Triggers, Views, and Schema Modification 1.
Data modeling using the entity-relationship model Winter 2006Ron McFadyen Entity-relationship model (ER model) P. 49: “This model and its variations.
관계 연산자 & SQL. Selection SELECT * FROM r WHERE A=B AND D>5.
SQL The relational DB Standard CS-450 Dr. Ali Obaidi.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1 CREATE/DROP/ALTER TABLE Data types : char, varchar, decimal, date CREATE TABLE DEPARTMENT.
Al-Imam University Girls Education Center Collage of Computer Science 1 ST Semester, 1432/1433H Chapter 8 Part 4 SQL-99 Schema Definition, Constraints,
Other SQL Query Examples
1 CS 430 Database Theory Winter 2005 Lecture 12: SQL DML - SELECT.
1 CSE 480: Database Systems Lecture 11: SQL. 2 SQL Query SELECT FROM WHERE –In MySQL, FROM and WHERE clauses are optional –Example:
Relational Algebra - Chapter (7th ed )
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra and Calculus.
CS 380 Introduction to Database Systems Chapter 7: The Relational Algebra and Relational Calculus.
Retrieve the names of all employees in department 5 who work more than 10 hours per week on the ‘ProductX’ project. p10ssn ← (Π essn (σ hours > 10 (works-on.
 Employee (fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno)  Department (dname, dnumber, mgrssn, mgrstartdate) 
Database Management Systems. NESTING OF QUERIES  Some queries require that existing values in the database be retrieved and then used in a comparison.
Fundamentals of Database Systems Fourth Edition El Masri & Navathe Instructor: Mr. Ahmed Al Astal Chapter 6 The Relational Algebra University Of Palestine.
Chapter 5-1 CSE 4701 In Class SQL Queries – Part II n Homework 3 from Spring 2015 n Problem 6.18 from the 6 th edition done in SQL and NOT relational expressions.
Logical Design database design. Dr. Mohamed Osman Hegaz2 Conceptual Database Designing –Provides concepts that are close to the way many users perceive.
莊裕澤資料庫基本概念 1 Yuh-Jzer Joung 莊 裕 澤 Dept. of Information Management National Taiwan University February, 2002 資料庫管理與資訊科技.
1 CSE 480: Database Systems Lecture 12: SQL (Nested queries and Aggregate functions)
Structured Query Language (2) The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems,
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 6 The Relational Algebra.
Slide 6- 1 Additional Relational Operations Aggregate Functions and Grouping A type of request that cannot be expressed in the basic relational algebra.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 10 A First Course in Database Systems.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
1Fundamentals of Database Systems 기본키에 밑줄을 그은 COMPANY 관계 데이타베이스 스키마 FNAMEMINITLNAMESSNBDATEADDRESSSEXSALARYSUPERSSNDNO EMPLOYEE DNAMEDNUMBERMGRSSNMGRSTARTDATE.
COMP163 Database Management Systems September 18, 2008 Lecture 8 – Sections SQL Queries.
Relational Algebra National University of Computer and Emerging Sciences Lecture # 6 June 30,2012.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
CS580 Advanced Database Topics Chapter 8 SQL Irena Pevac.
The Relational Algebra and Calculus
CS580 Advanced Database Topics
COP Introduction to Database Structures
Chapter # 6 The Relational Algebra and Calculus
Chapter 4 Basic SQL.
6/22/2018.
Retrieval Queries in SQL(DML)
11/9/2018.
Joining Tables ضم الجداول وإستخراج مناظر views منها الهدف : 1- استخراج المعلومات من جدولين أو اكثر بالإستفادة من الرابط بينهما وبإستخدام SQL 2- شروط قواعد.
Company Requirements.
Relational Algebra Sample Questions.
e. Retrieve the names of all employees who work on every project.
SQL-99: Schema Definition, Constraints, and Queries and Views
SQL Grouping, Ordering & Arithmetics Presented by: Dr. Samir Tartir
Presentation transcript:

Exercise 1 Relational Algebra 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’ WE > 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 DpE Depend_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))