sum()

Read(1535) Label: compute, sequence, sum,

Description:

Compute the sum of members of a sequence.

Syntax:

A.sum(x)

 

sum(x1,…,xn)

Equivalent to A.sum(), where x1,…,xn are members of sequence A

Note:

The function computes expression x with  members of sequence A and returns the sum of members. Ignore non-numeric members and treat null values as zero.

Parameter:

A

A sequence

x

 An expression whose result should be numeric type; can be omitted

Return value:

Numeric value

Example:

When A is a sequence

 

A

 

1

=[1,2,3,4].sum()

10

2

=[2,null,3,4].sum()

9; treat the null value as 0.

3

=[2, 3,4,"2323ads"].sum()

9; ignore non-numeric members.

4

=[1,2,3,4].sum(~*~)

30; return sum of members of a sequence obtained after the expression is computed.

5

=sum(1,2,3,4)

10, which is same as A1.

 

When A is a table sequence or a record sequence:

 

A

 

1

=demo.query("select * from EMPLOYEE")

 

2

=A1.sum(SALARY)

Compute sum of salaries of all employees.

3

=A1.(SALARY+100).sum()

Compute sum of SALARY values after salary of each employee is added 100.