Aggregates

Aggregates are used to compute a quantity over a collection of tuples: number, sum, maximum, minimum and average.

The basic form of an aggregate expression is:

function( type1 var1, type2 var2 , ... , typen varn
            | condition
            | expression )

The function is one of count, sum, max, min, avg. The variable declarations are sometimes called the dummies: they just indicate what we range over. Next comes the condition, a normal term from .QL. Finally, there is the expression.

Semantics for duplicate values

It is important to realize that the semantics of aggregates are in terms of sets of tuples that involve all the dummies. It is not the sum of the set of values computed by evaluating the indicated expressions. For example,

select sum(int x | x=0 or x=1 | 1)

returns 2 and not 1 (which would be the sum of the set {1}).

Maximum or minimum of empty set

When the set of tuples that satisfy the condition is empty, the maximum and minimum do not exist; no fictitious values (null, -infinity or infinity) are generated. For instance, the result of

select max(int i | i=0 and i=1 | i)

is simply an empty set: no tuples are returned.

Aggregates and recursion

There may be no recursive calls inside aggregates. For a full discussion of this issue, see the section on recursion.

Error messages relating to aggregates

Digg!Reddit!Del.icio.us!Facebook!Slashdot!Technorati!StumbleUpon!Ma.gnolia!

Comments
Only registered users can write comments!
 
< Prev


US and other patent applications pending.