This is no longer maintained and has been superseded by datajoint-company/datajoint-docs. Please file new issues there (or help contribute!). We are currently migrating and generating new content until December 2022 after which we’ll be decomissioning https://docs.datajoint.org and https://tutorials.datajoint.org in favor of https://datajoint.com/docs/.
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 university.Section.aggr(university.Enroll, 'count(*)->n') % Average grade in each course university.Course.aggr(university.Grade * university.LetterGrade, 'avg(points)->avg_grade')