/  Technology   /  Generalized Projection Operation, Aggregation Operation in Python

Generalized Projection Operation, Aggregation Operation in Python

 

Let’s consider the following table and understand these operations with examples.

R1 :    FACULTY-1

FNoFNameDNoQualSalary
22Riya21Ph.D55000
24Priya22M. Tech50000
25Zayn22M. Tech42000
27Harry23M. Tech28000
30Sia23M. Tech32000
33Max24Ph.D53000
35Fred24Ph.D52000
37Diva25M. Tech26000
39Ben25M. Tech24000
40Trent25M. Tech34000

 

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 :                

FName10% x Salary
Riya5500
Max5300
Fred5200

 

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

 

 

Leave a comment