Work on aggregates was done at the EECS department of UC Berkley, where the database management system, POSTGRES [RS87,SR86,SRH90], was designed and implemented. POSTGRES allows the user to specify aggregates in terms of state transition functions, where an aggregate is defined as a state, and state transition functions are used to define the computation of aggregates.
There are two types of state functions: sfunc1 and sfunc2. Here sfunc1 are state transition functions that compute the new state depending on the old state and value of the record. Sfunc2 are state transition functions that compute the new state dependent only on the old state. Sum is an example of an aggregate that uses only sfunc1, and count is an aggregate that uses only sfunc2. Average requires both a function to compute the running sum and a function to compute the running count. When all the records are processed, the final answer for the aggregate is sum divided by the count.
User uses initcond to define the initial state of the aggregate. Finalfunc is used to define the computation once all the records are processed.
Following example aggregate Average is written in POSTGRES and is taken from the POSTGRES user manual (http://pluto.xtech.ru/postgres95/users-guide/pg95user.html):
In the above example, int4pl, int4inc and int4div are built into POSTGRES. Int4pl adds the new value of the record to the current state and int4inc adds one to the state variable each time a record is processed. Int4div computes the average by dividing the first state variable be second state variable.