Databases Reference
In-Depth Information
Figure 2-13:
Properties of the Stream Aggregate operator.
Note that, in order to implement the
AVG
aggregation function, the Stream Aggregate
is computing both a
COUNT
and a
SUM
aggregate, the results of which will be stored in
the computed expressions
Expr1004
and
Expr1005
respectively. The Compute Scalar
verifies that there is no division by zero by using a
CASE
expression. As you can see in
the text plan, if
Expr1004
, which is the value for the count, is zero, the Compute Scalar
operator returns
NULL
, otherwise it calculates and returns the average by dividing the
sum by the count.