HP (Hewlett-Packard) c-tree-SQL ISQL and Tool reference Guide Printer User Manual


 
ISQL and Tools
3-22 FairCom Corporation
COMPUTE statements have no effect until you issue a BREAK statement with the same
break_spec.
Issuing the COMPUTE statement without any arguments displays the currently-set COM-
PUTE specifications, if any.
Arguments
AVG | MAX | MIN | SUM | COUNT
The function to apply to values of column_name. The functions AVG, MAX, MIN, and SUM
can be used only when the column is numeric. The function COUNT can be used for any col-
umn type.
column_name
The column whose value is to be computed. The column specified in column_name must also
be included in the select list of the query. If column_name is not also included in the select list,
it has no effect.
variable_name
Specifies the name of the variable where the computed value is stored. ISQL issues an implicit
DEFINE statement for variable_name and assigns the variable a value of zero. During query
processing, the value of variable_name changes as ISQL encounters the specified breaks.
break_spec
Specifies the set of rows after which ISQL processes the COMPUTE statement. A COMPUTE
statement has no effect until you issue a corresponding BREAK statement. See the description
of the BREAK statement in Section 3.7.2 "
BREAK" on page 3-13 for details.
Examples
The following example computes the number of items ordered by each customer.
ISQL> break on customer_name
ISQL> display col 5 "Number of orders placed by", customer_name, "=", n_ord on
customer_name
ISQL> compute count of order_id in n_ord on customer_name;
ISQL> select c.customer_name, o.order_id from customers c, orders o
where o.customer_id = c.customer_id;
CUSTOMER_NAME ORDER_ID
------------- --------
Sports Cars Inc. 1
Sports Cars Inc. 2
Number of orders placed by Sports Cars Inc.
= 2
Mighty Bulldozer Inc. 3
Mighty Bulldozer Inc. 4
Number of orders placed by Mighty Bulldozer Inc.
= 2
.
.
.