Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: Command Index > C

COMPUTE (Short Name: COMP)

Scroll Prev Top Next More

Use the COMPUTE command to calculate expressions or perform mathematical operations on columns.

 

COMPUTE

 

Options

 

,

Indicates that this part of the command is repeatable.

 

ALL

Executes all of the functions relevant to the data type of the selected column.

 

AVG

Computes the numeric average. R:BASE rounds averages of INTEGER values to the nearest integer value and CURRENCY values to their nearest unit.

 

colname

Specifies a column name. The column name is limited to 128 characters.

 

In a command, you can enter #c, where #c is the column number shown when the columns are listed with the LIST TABLES command. In an SQL command, a column name can be preceded by a table or correlation name and a period (tblname.colname).

 

COUNT

Determines how many non-null entries there are for a particular column item.

 

(expression)

Determines the value for the column using a text or arithmetic formula. The expression can include other columns from the table, constant values, functions, or system variables such as #date, #time, and #pi.

 

FROM tblview

Specifies the table or view.

 

MAXIMUM

Selects the maximum numeric, time, date, or alphabetic value. For the TEXT data type, R:BASE evaluates the first 30 characters.

 

MINIMUM

Selects the minimum numeric, time, date, or alphabetic value. For the TEXT data type, R:BASE evaluates the first 30 characters.

 

ROWS FROM tblname

Counts rows in a specified table.

 

STDEV

Computes standard deviation. Standard deviation is a measure of how widely values are dispersed from the average value.

 

SUM

Computes the numeric sum.

 

VARIANCE

Determines variance.

 

varname AS

Specifies a global variable name in which to store the result of a COMPUTE command. If you use the arguments COUNT or ROWS, the variable must be an INTEGER data type.

 

WHERE clause

Limits rows of data. For more information, see WHERE.

 

About the COMPUTE Command

 

R:BASE does not consider null values when it calculates averages, minimums, maximums, counts, sums, standard deviation, and variance.

 

The COMPUTE command can define a global variable with the data type that matches the results of the computation of a column's values.

 

You can also choose Calculate on the Data Browser menu in R:BASE for Windows to choose a column, then perform the mathematical operations that apply to the data type of the column.

 

It is recommended to use the SELECT Function(Column) notation over the COMPUTE notation as this provides greater compliance to the SQL standard and greater portability to new versions of R:BASE.

 

Examples

 

The following command computes, then stores the minimum on-hand quantity in the vminvar variable found in the prodlocation table.

 

COMPUTE vminvar AS MINIMUM onhand FROM prodlocation

 

The following command computes the total number of rows in the transmaster table and places the result in the vrowcounter variable.

 

COMPUTE vrowcounter AS ROWS FROM transmaster

 

The following command computes the average of an INTEGER data type (onhand) and returns the result as a DOUBLE data type.

 

COMPUTE AVG (onhand * 1.0) FROM prodlocation

 

The following command calculates your multiple computations on different columns. The command counts the number of entries in the custid column and averages the entries in the netamount column. The custid column and the netamount column are both from the transmaster table; all the specified columns must be in the same table or view.

 

COMPUTE COUNT custid, AVG netamount FROM transmaster

 

The command below shows you how to use variables to hold the results of computations.

 

COMPUTE v1 AS COUNT custid,v2 AS AVG netamount FROM transmaster