Explain the difference between using functions along with and without grouping attributes in relational algebra. Give examples.
Ans: Group functions are used to group data of similar type.
GAMMA = grouping and aggregation
Applying GAMMAL(R)
• Group R according to all the grouping attributes on list L.
1. That is: form one group for each distinct list of values for those attributes in R.
• Within each group, compute AGG(A ) for each aggregation on list L.
• Result has one tuple for each group:
1. The grouping attributes and
2. Their group's aggregations.
Example: Grouping /Aggregation
R = ( A B C )
1 2 3
4 5 6
1 2 5
GAMMAA,B,AVG(C) (R) = ?
First, group R by A and B :
A B C
1 2 3
1 2 5
4 5 6
Then, average C within groups:
A B AVG(C)
1 2 4
4 5 6