Ch. 4 Relational Algebra (2) Exercises. Algebra (3) 데이터베이스시스템 2 Queries in Ch.4 (p.161, p.166) EMPLOYEE (p.161) EmpNoEmpNameTitleManagerSalaryDNO 2106.

Slides:



Advertisements
Similar presentations
Chapter 6 The Relational Algebra
Advertisements

Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 (Continued) The Relational Algebra and Calculus.
Chapter 6 Additional Relational Operations Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
SQL Subqueries Objectives of the Lecture : To consider the general nature of subqueries. To consider simple versus correlated subqueries. To consider the.
AGGREGATE FUNCTIONS Prof. Sin-Min Lee Surya Bhagvat CS 157A – Fall 2005.
Set operators (UNION, UNION ALL, MINUS, INTERSECT) [SQL]
Database Systems Chapter 6 ITM Relational Algebra The basic set of operations for the relational model is the relational algebra. –enable the specification.
Copyright © 2004 Pearson Education, Inc.. Chapter 6 The Relational Algebra and Relational Calculus.
The Relational Algebra and Calculus. Relational Algebra Overview Relational algebra is the basic set of operations for the relational model These operations.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra and Calculus.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Chapter 3 Introduction to SQL Yonsei University 1 st Semester, 2015 Sanghyun Park.
Relational Algebra Example Database Application (COMPANY) Relational Algebra –Unary Relational Operations –Relational Algebra Operations From Set Theory.
Final Review Dr. Bernard Chen Ph.D. University of Central Arkansas.
Relational Model Concepts. The relational model represents the database as a collection of relations. Each relation resembles a table of values. A table.
1 ICS 184: Introduction to Data Management Lecture Note 10 SQL as a Query Language (Cont.)
Relational Algebra - Chapter (7th ed )
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra and Calculus.
METU Department of Computer Eng Ceng 302 Introduction to DBMS The Relational Algebra by Pinar Senkul resources: mostly froom Elmasri, Navathe and other.
ACTION QUERIES (SQL COMMANDS ) STRUCTURED QUERY LANGUAGE.
SELECT Statements Lecture Notes Sree Nilakanta Fall 2010 (rev)
Structured Query Language. Group Functions What are group functions ? Group Functions Group functions operate on sets of rows to give one result per group.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Oracle DML Dr. Bernard Chen Ph.D. University of Central Arkansas.
Relational Algebra. 2 Outline  Relational Algebra Unary Relational Operations Relational Algebra Operations from Set Theory Binary Relational Operations.
SQL SeQueL -Structured Query Language SQL SQL better support for Algebraic operations SQL Post-Relational row and column types,
Basic Group Functions (without GROUP BY clause) Week 5 – Chapter 5.
Chapter 6 The Relational Algebra Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
SQL 연습 2 pp SQL 연습 데이터베이스시스템 2 Data (EMPL & DEPT) p.194 EmpNoEmpNameTitleManagerSalaryDNO 조민희과장 김상원사원
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
The Relational Algebra. Slide 6- 2 Outline Relational Algebra Unary Relational Operations Relational Algebra Operations From Set Theory Binary Relational.
An Introduction To SQL Part 2 (Special thanks to Geoff Leese)
1 Information Retrieval and Use (IRU) An Introduction To SQL Part 2.
1 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Dr. Mohamed Hegazi1 The Relational Algebra and Relational Calculus.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
Agenda for Class - 03/04/2014 Answer questions about HW#5 and HW#6 Review query syntax. Discuss group functions and summary output with the GROUP BY statement.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
1 CSE 480: Database Systems Lecture 16: Relational Algebra.
SQL Aggregeringsfunktioner. AGGREGATE FUNCTIONS Include COUNT, SUM, MAX, MIN, and AVG Query 15: Find the maximum salary, the minimum salary, and the average.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus تنبيه : شرائح العرض.
Advanced SQL. SQL - Nulls Nulls are not equal to anything - Null is not even equal to Null where columna != ‘ABC’ --this will not return records where.
Database Systems Chapter 6
The Relational Algebra and Relational Calculus
Relational Algebra Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Relational Algebra Lecture 2.
CS 480: Database Systems Lecture 12 February 11, 2013.
Chapter # 6 The Relational Algebra and Calculus
Fundamental of Database Systems
Chapter 3 Introduction to SQL(3)
Working with Tables: Join, Functions and Grouping
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 6: Relational Algebra Fall 2015 Dr. Abdullah Almutairi
Generalization.
RELATIONAL ALGEBRA (Chapter 2)
376a. Database Design Dept. of Computer Science Vassar College
CS 3630 Database Design and Implementation
Chapter 2: Intro to Relational Model
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
Database Programming Using Oracle 11g
Presentation transcript:

Ch. 4 Relational Algebra (2) Exercises

Algebra (3) 데이터베이스시스템 2 Queries in Ch.4 (p.161, p.166) EMPLOYEE (p.161) EmpNoEmpNameTitleManagerSalaryDNO 2106 김창섭대리 10032,500, 박영권과장 43773,000, 이수민부장 43774,000, 조민희과장 43773,000, 최종철사원 30111,500, 김상원사원 34261,500, 이성래사장 5,000,0002 DEPARTMENT (p.166) DeptNoDeptNameFloor 1 영업 8 2 기획 10 3 개발 9 4 총무 7

Algebra (3) 데이터베이스시스템 3 Queries in Ch.4 (p.161, p.166) EMPL (EmpNo, EmpName, Title, Manager, Salary, DNO) (p.161) DEPT (DeptNo, DeptName, Floor) (p.166) Q (p.160) List all the information of employees who work for the department numbered 3 EMPL where DNO = 3 Q (p.162) List all the titles of employees. EMPL [Title]

Algebra (3) 데이터베이스시스템 4 EMPL (EmpNo, EmpName, Title, Manager, Salary, DNO) DEPT (DeptNo, DeptName, Floor) Q (p.164) List DeptNo of the department for which ' 김창섭 ' works or that of the department ' 개발 ' (EMPL where EmpName= ' 김창섭 ') [DNO] Union (DEPT where DeptName= ' 개발 ') [DeptNo] Q (p.165) List DeptNos of departments for which ' 김창섭 ' or ' 최종철 ' works and that of the department ' 기획 ' (EMPL where EmpName = ' 김창섭 ' or EmpName= ' 최종철 ') [DNO] Intersect (DEPT where DeptName= ' 기획 ') [DeptNo]

Algebra (3) 데이터베이스시스템 5 EMPL (EmpNo, EmpName, Title, Manager, Salary, DNO) DEPT (DeptNo, DeptName, Floor) Q (p.166) List DeptNos of departments without any employees in it. DEPT [DeptNo] – EMPL [DNO] Q (p.168) Get the Cartesian product of EMPL and DEPT. EMPL X DEPT (degree: 9, cardinality: 28) Q (p.169) Get the equi-Join of Employee relation and Department relation (EMPL X DEPT) where DNO = DeptNo

Algebra (3) 데이터베이스시스템 6 EMPL (EmpNo, EmpName, Title, Manager, Salary, DNO) DEPT (DeptNo, DeptName, Floor) Q (p.171) Get the natural join of EMPL and DEPT (EMPL rename DNO as DeptNo) join DEPT (degree: 8, cardinality: 7) Q (p.172) List the names and salaries of employees who work for departments of DeptNo 2 or 3. (EMPL where DNO=2 or DNO=3) [EmpName, Salary] Q (p.173) List the names of employees who work for the department ' 개발 ' ( (EMPL rename DNO as DeptNo) join (DEPT where DeptName= ' 개발 ') ) [EmpName]

Algebra (3) 데이터베이스시스템 7 EMPL (EmpNo, EmpName, Title, Manager, Salary, DNO) DEPT (DeptNo, DeptName, Floor) 집단함수 : SUM, AVG, MAX, MIN, COUNT (p.174) Q (p.174) Get the average salary of all the employees summarize EMPL per{ } add Avg(Salary) (degree: 1, cardinality: 1) summarize EMPL per{ } add Avg(Salary) as Avg_Sal Q (p.175) List the average salary of the employees for each department. summarize EMPL per{DNO} add Avg(Salary) as Avg_Sal (degree: 2, cardinality: #of departments=3)

Algebra (3) 데이터베이스시스템 8

Algebra (3) 데이터베이스시스템 9 Query set A (pp.526–534) EMPL (EmpNo, EmpName, Title, Manager,Salary, HireDate, DNO) DEPT (DeptNo, DeptName, Floor) Q1 : List the department names and DeptNos of all the departments. DEPT [DeptName, DeptNo] Q2 : Get all the detail of EMPL relation EMPL Q4 : List names and titles of employees who work for the department with number 3. (EMPL where DNO=3) [EmpName, Title]

Algebra (3) 데이터베이스시스템 10 Query set A (pp.526–534) EMPL (EmpNo, EmpName, Title, Manager, Salary, HireDate, DNO) DEPT (DeptNo, DeptName, Floor) Q6 : List names and HireDates of employees who joined the company since Feb. 1, (EMPL where HireDate >= ‘ ’) [EmpName, HireDate] Q7 : Get all the names and titles of employees who are not ' 과장 ' (EMPL where Title <> ' 과장 ') [EmpName, Title] Q9 : List names, titles, and salaries of employees whose salaries are between 2,000,000 and 3,000,000 (EMPL where Salary>= and Salary <= ) [EmpName, Title, Salary]

Algebra (3) 데이터베이스시스템 11 Query set A (pp.526–534) EMPL (EmpNo, EmpName, Title, Manager, Salary, HireDate, DNO) DEPT (DeptNo, DeptName, Floor) Q12 : List names, titles, and DNO’s of employees who work for department 2 as either a ' 대리 ' or a ‘ 과장 '. (EMPL where DNO=2 and (Title= ‘ 대리 ' or Title= ' 과장 ') ) [EmpName, Title, DNO] Q13 : Get all names and titles of employees whose name starts with ' 김 ' (EMPL where EmpName like ' 김 %’) [EmpName, Title] Q14 : Get the name and the title of the highest manager (EMPL where Manager is NULL) [EmpName, Title] Q15, Q16, Q17: EMPL [EmpName, Title]

Algebra (3) 데이터베이스시스템 12 Query set A (pp.526–534) EMPL (EmpNo, EmpName, Title, Manager, Salary, HireDate, DNO) DEPT (DeptNo, DeptName, Floor) Q18 : Get the number of employees who work in the department 3 and their average salary summarize (EMPL where DNO=3) per{ } add (Count(*) as Num_Emp, Avg(Salary) as Avg_Sal) Q20 : List names and Titles of employees who work in the department ' 개발 ' ( (EMPL rename DNO as DeptNo) join (DEPT where DeptName= ' 개발 ') ) [EmpName, Title]

Algebra (3) 데이터베이스시스템 13 Query set A (pp.526–534) EMPL (EmpNo, EmpName, Title, Manager, Salary, HireDate, DNO) DEPT (DeptNo, DeptName, Floor) Q23 : Get the names of employees who earn more than the average salary of all the employees ( (EMPL X (summarize EMPL per{ } add Avg(Salary) as Avg_Sal) ) where Salary > Avg_Sal) [EmpName] Q27 : List the DeptNo, department_names, and floors of the departments in which nobody works (DEPT[DeptNo] – (EMPL rename DNO as DeptNo) ) Join DEPT DEPT – (DEPT join (EMPL rename DNO as DeptNo) ) [DeptNo, DeptName, Floor]

Algebra (3) 데이터베이스시스템 14