

Proposed in Ozsoyoglu, Ozsoyoglu, & Mata (1985, 1987), the aggregationbytemplate operator groups tuples of R_{1} as follows. Let t be a tuple over attributes (X ∪ Z) such that t[X] = t_{1}[X] for some t_{1} in R_{1} and t[Z] = t_{2}[Z] for some tuple t_{2} in R_{2}.
Each such tuple t defines a group G_{t} of tuples of R_{1} such that a tuple v, with v ∊ R1, is in G_{t} if v[X] = t[X], v[Y_{a}] ∊ t[Z_{a}] and v[Y_{n}] ⊆ t[Z_{n}]. Then f is applied to attribute A of tuples in G_{t}.
The value returned by f applied over an empty group is null. Formally:
Let R_{1}, R_{2} ∊ A, Y ⊆ Atr (R_{1}), Z = Atr (R_{2}), where  Y  =  Z  ≥ 1, and is defined as:
Aggregationbytemplate is more convenient than aggregate formation when there are prespecified groupings of attributes for aggregation (common in statistical database applications). Also, aggregationbytemplate is based on grouping tuples (i.e., a tuple may belong to more than one group) while aggregate formation is based on partitioning tuples. However, each aggregation operator is expressible by an algebra expression utilizing the other aggregation operator.

