Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- SIx Driver RDD v3.00 - Reference Guide - <b>average:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
  AVERAGE:

  Syntax:

  AVERAGE <nExp list> TO <idVar list>
          [<scope>] [WHILE <lCondition>] [FOR <lCondition>]
          [NOOPTIMIZE]

  <nExp list> is a list of the numeric fields to AVERAGE for each record
  processed.

  <idVar list> identifies the receiving variables to assign the average
  results to.  Variables that either do not exist or are not visible are
  created as private variables. <idVar list> must contain the same number of
  elements as <nExp list>.

  <scope> defines the portion of the current database file to AVERAGE.
  The default scope is ALL.  Mach SIx only supports the ALL scope.

  WHILE <lCondition> specifies the set of records meeting the condition
  from the current record until the condition fails.  Mach SIx does not
  support a WHILE condition.

  FOR <lCondition> specifies the conditional set of records to AVERAGE
  within the given scope.  Mach SIx will optimize any FOR condition that
  contains one or more active index keys.

  NOOPTIMIZE preempts optimization and forces default Clipper processing.

  Description:

  AVERAGE averages one or more numeric expressions to variables for a range
  of records in the current database file.  Zero values are counted in the
  AVERAGE unless explicitly ruled out with a FOR condition.

  The AVERAGE command may be optimized by specifying one or more active
  index keys in the FOR condition.  Note that Mach SIx will only optimize
  the AVERAGE command when used with a command with a FOR condition.
  Specifying a WHILE condition or a SCOPE other than ALL will cancel
  optimization.

  ---------------------------------| EXAMPLE |--------------------------------
  /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  *  Demonstrates optimized AVERAGE command                                 *
  *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

  #include "SIXCDX.CH"
  #include "MACHSIX.CH"

  LOCAL nAvg := 0

  USE Account VIA "SIXCDX"  // Structural index ACCOUNT.CDX opened
                            // automatically
  CLEAR SCREEN
  ? "Example of optimized AVERAGE command."
  ?

  // Fully optimized average of account balances, taking
  // advantage of the STATE index tag
  AVERAGE account->BALANCE TO nAvg FOR account->STATE = "CA"

  ? "Average account balance for California.", nAvg

  // Fully optimized average of income, making use of
  // multiple index tags
  AVERAGE account->INCOME TO nAvg  FOR (Age >= 20 .AND. Age < 30) .AND. ;
                                      State = "AK" .and. City = "Sicily"

  ? "Average income for those twenty-something people in Sicily, Alaska.",;
     nAvg

  // Partially optimized average of age, for Orlando residents born in 1972.
  // Note that Year( BirthDate ) could not be optimized because there was
  // not an index built on this expression. Year( BirthDate ) is an example
  // of a non-indexed expression.

  AVERAGE Age TO nAvg FOR City = "Orlando" .AND. Year( BirthDate ) = 1972
  ? "Average age:", nAvg

  CLOSE ALL
  // End of example program



See Also: TOTAL SUM

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson