Difference between revisions of "SUM"

From Lianjapedia
Jump to: navigation, search
(Description)
 
(11 intermediate revisions by 4 users not shown)
Line 3: Line 3:
  
 
==Syntax==
 
==Syntax==
SUM [<scope>] [<expN1> [,<expN2>....]]
+
SUM  
  
[TO <memvar list>][FOR <condition>]
+
[IN <workarea>|<alias>]
 +
 
 +
[<scope>]
 +
 
 +
<expN1> [,<expN2>....]
 +
 
 +
TO <memvar list> | to ARRAY <array>
 +
 
 +
[FOR <condition>]
  
 
[WHILE <condition>]
 
[WHILE <condition>]
  
 
==See Also==
 
==See Also==
[[AVERAGE]], [[COUNT]], [[TOTAL]]
+
[[AVERAGE]], [[COUNT]], [[TOTAL]], [[CALCULATE]]
  
 
==Description==
 
==Description==
The SUM command totals the specified numeric expressions with respect to the records in the currently selected table.  If <scope> is not specified, then ALL is used, unless the WHILE clause is specified, in which case the <scope> will default to REST.  Up to fifteen numeric expressions can be summed.  You can specify different target memory variables, with comma separators, for storing the different expressions.  If SET DELETED ON is in effect, then records that are marked for deletion will not be included in the calculations.  If a FILTER <condition> is active, then only those records that satisfy the <condition> will be included in the calculations.  If the target memory variables do not exist, then they will be automatically created.
+
The SUM command totals the specified numeric expressions with respect to the records in the currently selected table.  If <scope> is not specified, then ALL is used, unless the WHILE clause is specified, in which case the <scope> will default to REST.  Up to fifteen numeric expressions can be summed.  If SET DELETED ON is in effect, then records that are marked for deletion will not be included in the calculations.  If a FILTER <condition> is active, then only those records that satisfy the <condition> will be included in the calculations.   
 +
 
 +
====IN <workarea>|<alias>====
 +
If the workarea number, letter or alias name is specified, the SUM is carried out in that workarea.  Note, the IN clause must be the first clause.  From v6.0.
  
 
====TO <memvar list>====
 
====TO <memvar list>====
If the TO <memvar list> clause is not specified, then the results are displayed on the screen only if TALK is ON.  If TALK is OFF, then a <memvar list> must be specified so that the results are accessible.
+
If the TO <memvar list> clause is specified, then the results are stored to the memory variables in the comma-separated <memvar list>.  If the target memory variables do not exist, then they will be automatically created.
 +
 
 +
====TO ARRAY <array>====
 +
The TO ARRAY clause is used to store the SUM results in a one-dimensional array.  The result of the first numeric expression is placed in the first array element; the second result is placed in the second element, and so on.  If there are fewer elements than expressions, the SUM command will only store results for which there are elements.  If there are more elements than expressions, the remaining elements are left empty.  The array must be pre-declared.
  
 
====FOR <condition>====
 
====FOR <condition>====
Line 23: Line 37:
 
====WHILE <condition>====
 
====WHILE <condition>====
 
The WHILE <condition> can be used in conjunction with the FIND or SEEK commands, and the REST <scope>, to restrict the number of records which are processed and therefore optimize the performance of the SUM command.
 
The WHILE <condition> can be used in conjunction with the FIND or SEEK commands, and the REST <scope>, to restrict the number of records which are processed and therefore optimize the performance of the SUM command.
 
====TO ARRAY <array>====
 
The TO ARRAY clause is used to store the SUM results in a one-dimensional array.  The result of the first numeric expression is placed in the first array element; the second result is placed in the second element, and so on.  If there are fewer elements than expressions, the SUM command will only store results for which there are elements.  If there are more elements than expressions, the remaining elements are left empty.
 
  
 
==Example==
 
==Example==
Line 38: Line 49:
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Commands]]
 
[[Category:Commands]]
[[Category:Table Basics]]
+
[[Category:NoSQL Commands]]
[[Category:Table Basics Commands]]
+
[[Category:Data Commands]]
+

Latest revision as of 08:16, 4 January 2021

Purpose

Sum numeric expressions against records in the currently selected table

Syntax

SUM

[IN <workarea>|<alias>]

[<scope>]

<expN1> [,<expN2>....]

TO <memvar list> | to ARRAY <array>

[FOR <condition>]

[WHILE <condition>]

See Also

AVERAGE, COUNT, TOTAL, CALCULATE

Description

The SUM command totals the specified numeric expressions with respect to the records in the currently selected table. If <scope> is not specified, then ALL is used, unless the WHILE clause is specified, in which case the <scope> will default to REST. Up to fifteen numeric expressions can be summed. If SET DELETED ON is in effect, then records that are marked for deletion will not be included in the calculations. If a FILTER <condition> is active, then only those records that satisfy the <condition> will be included in the calculations.

IN <workarea>|<alias>

If the workarea number, letter or alias name is specified, the SUM is carried out in that workarea. Note, the IN clause must be the first clause. From v6.0.

TO <memvar list>

If the TO <memvar list> clause is specified, then the results are stored to the memory variables in the comma-separated <memvar list>. If the target memory variables do not exist, then they will be automatically created.

TO ARRAY <array>

The TO ARRAY clause is used to store the SUM results in a one-dimensional array. The result of the first numeric expression is placed in the first array element; the second result is placed in the second element, and so on. If there are fewer elements than expressions, the SUM command will only store results for which there are elements. If there are more elements than expressions, the remaining elements are left empty. The array must be pre-declared.

FOR <condition>

If a FOR <condition> is specified, then only those records which satisfy the <condition> are included in the calculations.

WHILE <condition>

The WHILE <condition> can be used in conjunction with the FIND or SEEK commands, and the REST <scope>, to restrict the number of records which are processed and therefore optimize the performance of the SUM command.

Example

use patrons
sum seats to m_seats;
  for event = "BALLET" and date = date()
? m_seats
      1680