Generalized Projection Operation, Aggregation Operation in Python
Let’s consider the following table and understand these operations with examples.
R1 : FACULTY-1
FNo | FName | DNo | Qual | Salary |
22 | Riya | 21 | Ph.D | 55000 |
24 | Priya | 22 | M. Tech | 50000 |
25 | Zayn | 22 | M. Tech | 42000 |
27 | Harry | 23 | M. Tech | 28000 |
30 | Sia | 23 | M. Tech | 32000 |
33 | Max | 24 | Ph.D | 53000 |
35 | Fred | 24 | Ph.D | 52000 |
37 | Diva | 25 | M. Tech | 26000 |
39 | Ben | 25 | M. Tech | 24000 |
40 | Trent | 25 | M. Tech | 34000 |
Generalized Projection Operation ( P ) :
This operation allows arithmetic operations or string operations in the attribute list of projection operations.
Example-1 : Find the list of FName having PhD degree and their 10 % of Salaries.
P FName, Salary ¸ 10 (sQual = ‘PhD’ (Faculty-1)
Output :
FName | 10% x Salary |
Riya | 5500 |
Max | 5300 |
Fred | 5200 |
Aggregation Operation : ( )
Aggregate Function takes a collection of values and returns a single value as a result.
Example-2 : Find the sum of the salaries of all the faculty.
(Faculty-1)
sum(Salary)
Output : 396000
Example-3 : Find the average of the salaries of all the faculty
(Faculty-1)
average(Salary)
Output : 39600