Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

AVERAGE Command

Visual Studio .NET 2003

Computes the arithmetic mean of numeric expressions or fields.

AVERAGE [ExpressionList]   [Scope] [FOR lExpression1] [WHILElExpression2]
   [TO VarList | TO ARRAY ArrayName]   [NOOPTIMIZE] 

Parameters

ExpressionList
Specifies the expressions to average. ExpressionList can be a list of fields from the table separated by commas, or numeric expressions involving fields from the table.
Scope
Specifies the record or range of records to include in the average. Only the records that fall within the range of records specified by the scope are averaged. The scope clauses are: ALL, NEXT nRecords, RECORD nRecordNumber, and REST. The default scope for AVERAGE is ALL records.

Commands that include Scope operate only on the table in the active work area.

FOR lExpression1
Specifies a condition whereby only the records that satisfy the logical condition lExpression are included. This argument allows you to filter out undesired records.

Rushmore optimizes an AVERAGE FOR query if lExpression is an optimizable expression. For best performance, use an optimizable expression in the FOR clause. For information on Rushmore optimizable expressions, see SET OPTIMIZE and Using Rushmore to Speed Data Access.

WHILE lExpression2
Specifies that as long as the logical expression lExpression2 evaluates to true (.T.), records are included in the average.
TO VarList
Specifies the list of variables or array elements to which the results of the average are stored.
TO ARRAY ArrayName
Specifies the one-dimensional array to which the results of the average are stored. The one-dimensional array can be created before the execution of AVERAGE.

If the array you include in AVERAGE doesn't exist, Visual FoxPro automatically creates it. If the array exists and isn't large enough to contain all the results, Visual FoxPro increases the size of the array automatically to accommodate the information.

NOOPTIMIZE
Disables Rushmore optimization of AVERAGE. For more information, see SET OPTIMIZE and Using Rushmore to Speed Data Access.

Remarks

All numeric fields in the selected table are averaged unless you include an optional expression list. The result is displayed on the screen if SET TALK is ON. If SET HEADINGS is ON, the field names or expression involving the field names are displayed above the results.

Example

CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE orders  && Open order table

CLEAR
AVERAGE Order_Amt  && Calcuate averages of all orders
AVERAGE Order_Amt TO gnAvg  && Store average to memory variable
? 'Average order amount: '
?? gnAvg  && Display the average again

See Also

CALCULATE | DIMENSION | SET HEADINGS | SUM | Using Rushmore to Speed Data Access | SET OPTIMIZE

Show:
© 2014 Microsoft. All rights reserved.