xHarbour Reference Documentation > Command Reference xHarbour Developers Network  

AVERAGE

Calculates the average of numeric expressions in the current work area.

Syntax

AVERAGE <expressions,...> ;
     TO <resultVarNames,...> ;
       [<Scope>] ;
 [WHILE <lWhileCondition>] ;
   [FOR <lForCondition>]

Arguments

AVERAGE <expressions,...>
This is a comma separated list of numeric expressions that are evaluated for the records of the current work area.
TO <resultVarNames,...>
A comma separated list of variable names that are assigned the results of the calculation. The number of <resultVarNames,...> must match exactly the number of <expressions,...>.
<Scope>
This option defines the number of records to process. It defaults to ALL. The NEXT <nCount> scope processes the next <nCount> records.
WHILE <lWhileCondition>
This is a logical expression indicating to continue calculation while the condition is true. The AVERAGE operation stops as soon as <lWhileCondition> yields .F. (false).
FOR <lForCondition>
This is a logical expression which is evaluated for all records in the current work area. Those records where <lForCondition> yields .T. (true) are included in the calculation.

Description

The AVERAGE command is used to calculate average values for one or more numeric expressions. The expressions are evaluated in the current work area. The number of records to include in the calculation can be restricted using a FOR and/or WHILE condition or by explicitely defining a scope.

Info

See also:COUNT, DbEval(), SUM, TOTAL
Category: Database commands
Source:rdd\dbcmd.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// This example calculates the average payments for the first half
// of this year:

   PROCEDURE Main
      LOCAL nAvg

      USE Sales NEW

      AVERAGE Payment TO nAvg FOR Month(SALEDATE) < 7 .AND. ;
                                   Year(SALEDATE) == Year(Date())
      USE

      ? nAvg
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe