outline - emory university
TRANSCRIPT
![Page 1: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/1.jpg)
Outline
� Relational Algebra
� Unary Relational Operations� Select, Project
� Relational Algebra Operations From Set Theory� Union, Intersection, Difference, Cartesian Product
� Binary Relational Operations� Join, Set Division
35
� Join, Set Division
� Additional Relational Operations� Generalized project, Aggregates, Outer Join
� Examples and exercise
� Relational Calculus
� Tuple Relational Calculus
� Coming up� SQL
![Page 2: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/2.jpg)
Additional Relational Operations –
Generalized projection
� Allows functions of attributes to be included in the
projection list
36
� Example
πLNAME, FNAME, SALARY*1.03 (EMPLOYEE)
![Page 3: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/3.jpg)
Additional Operations – Aggregate Functions
� An aggregate functions operates on a collection of
values (tuples) from the database and computes one
single value as output.
� Common functions include SUM, AVERAGE,
MAXIMUM, and MINIMUM and COUNT.
37
MAXIMUM, and MINIMUM and COUNT.
![Page 4: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/4.jpg)
Aggregate Functions and Grouping
� Groups the tuples by the values of some attributes and then
apply an aggregate function independently to each group
38
![Page 5: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/5.jpg)
Aggregation and Grouping – Formal
Notation
39
![Page 6: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/6.jpg)
40
![Page 7: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/7.jpg)
41
![Page 8: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/8.jpg)
Operations of Relational Algebra
42
![Page 9: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/9.jpg)
Operations of Relational Algebra
43
![Page 10: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/10.jpg)
Complete Set of Relational Operations
� The set of operations including select σσσσ, project ππππ , union ∪∪∪∪, set difference - , and cartesian product Xis called a complete set because any other relational algebra expression can be expressed by a combination of these five operations.
44
� For example:
R ∩∩∩∩ S = (R ∪∪∪∪ S ) – ((R −−−− S) ∪∪∪∪ (S −−−− R))
R <join condition>S = σσσσ <join condition> (R X S)
![Page 11: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/11.jpg)
Additional Operations
� Generalized Projections
� Aggregate and Groupings
� Outer Joins
45
![Page 12: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/12.jpg)
Examples of Queries
in Relational Algebra
46
![Page 13: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/13.jpg)
Examples of Queries
in Relational Algebra
47
![Page 14: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/14.jpg)
1. Find fname and lname of all employees who have 2 or more
dependents
48
![Page 15: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/15.jpg)
1. Find fname and lname of all employees who have 2 or more
dependents
49
![Page 16: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/16.jpg)
2. Find fname and lname of the employees who have the most
number of dependents
50
![Page 17: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/17.jpg)
2. Find fname and lname of the employees who have the most
number of dependents
51
![Page 18: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/18.jpg)
3. Find fname and lname of the employee(s) in the ‘Research’
department who earn the highest salary in the department
52
![Page 19: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/19.jpg)
3. Find fname and lname of the employee(s) in the ‘Research’
department who earn the highest salary in the department
53
![Page 20: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/20.jpg)
4. For each department, show the name, number of employees,
minimum salary and maximum salary paid to the employees in
the department
54
![Page 21: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/21.jpg)
4. For each department, show the name, number of employees,
minimum salary and maximum salary paid to the employees in
the department
55
![Page 22: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/22.jpg)
Exercise
5. Find fname and lname of all employees who work on more projects than ‘John Smith’
6. Find fname and lname of all employees who work on 2 or more projects controlled by the ‘Research’ department
7. Find fname and lname of all employees who work on all
56
7. Find fname and lname of all employees who work on all projects controlled by the ‘Research’ department
8. Find fname and lname of all employeeds that do not work on any projects controlled by the ‘Research’ department
![Page 23: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/23.jpg)
5. Find fname and lname of all employees who work on more
projects than ‘John Smith’
57
![Page 24: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/24.jpg)
6. Find fname and lname of all employees who work on 2 or more
projects controlled by the ‘Research’ department
58
![Page 25: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/25.jpg)
7. Find fname and lname of all employees who work on all projects controlled by the ‘Research’ department
59
![Page 26: Outline - Emory University](https://reader031.vdocument.in/reader031/viewer/2022011815/61d4f020abb1b232424fe785/html5/thumbnails/26.jpg)
8. Find fname and lname of all employeeds that do not work on any projects controlled by the ‘Research’ department
60