Aggregation, performed with the
aggr operator, is a special form of
proj with the additional feature of allowing aggregation calculations on another table.
It has the form
tab.aggr(other, ...) where
other is another table.
Without the argument
proj are exactly equivalent.
Aggregation allows adding calculated attributes to each entity in
tab based on aggregation functions over attributes in the matching entities of
Aggregation functions include
var, and others.
Aggregation functions can only be used in the definitions of new attributes within the
proj, the output of
aggr has the same entity class, the same primary key, and the same number of elements as
Primary key attributes are always included in the output and may be renamed, just like in
# Number of students in each course section Section.aggr(Enroll, n="count(*)") # Average grade in each course Course.aggr(Grade * LetterGrade, avg_grade="avg(points)")