Skip to main content

COUNT

COUNT(recordset [ , expression ] [, KEYED ] [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )

COUNT(valuelist )

recordsetThe set of records to process. This may be the name of a DATASET or a record set derived from some filter condition, or any expression that results in a derived record set, or a the name of a DICTIONARY declaration. This also may be the GROUP keyword to indicate counting the number of elements in a group, when used in a RECORD structure to generate crosstab statistics.
expressionOptional. A logical expression indicating which records to include in the count. Valid only when the recordset parameter is the keyword GROUP to indicate counting the number of elements in a group.
KEYEDOptional. Specifies the activity is part of an index read operation, which allows the optimizer to generate optimal code for the operation.
UNORDEREDOptional. Specifies the output record order is not significant.
ORDEREDSpecifies the significance of the output record order.
boolWhen False, specifies the output record order is not significant. When True, specifies the default output record order.
STABLEOptional. Specifies the input record order is significant.
UNSTABLEOptional. Specifies the input record order is not significant.
PARALLELOptional. Try to evaluate this activity in parallel.
numthreadsOptional. Try to evaluate this activity using numthreads threads.
ALGORITHMOptional. Override the algorithm used for this activity.
nameThe algorithm to use for this activity. Must be from the list of supported algorithms for the SORT function's STABLE and UNSTABLE options.
valuelistA comma-delimited list of expressions to count. This may also be a SET of values.
Return:COUNT returns a single value.

The COUNT function returns the number of records in the specified recordset or valuelist.

Example:

MyCount := COUNT(Trades(Trades.trd_rate IN ['3', '4', '5']));
   // count the number of records in the Trades record
   // set whose trd_rate field contains 3, 4, or 5
R1 := RECORD
  person.per_st;
  person.per_sex;
  Number := COUNT(GROUP);
   //total in each state/sex category
  Hanks := COUNT(GROUP,person.per_first_name = 'HANK');
   //total of "Hanks" in each state/sex category
  NonHanks := COUNT(GROUP,person.per_first_name <> 'HANK');
   //total of "Non-Hanks" in each state/sex category
END;
T1 := TABLE(person, R1,  per_st, per_sex);
Cnt1    := COUNT(4,8,16,2,1); //returns 5
SetVals := [4,8,16,2,1];
Cnt2    := COUNT(SetVals); //returns 5

See Also: SUM, AVE, MIN, MAX, GROUP, TABLE