count()
Calculates the number of records in a group.
c is an alias for count.
Syntax
count
count(EXPR)
count(EXPR)
Parameters
EXPR- (Optional) An expression that returns the field to check for null. When specified, only counts records where the value of
EXPRis not null.
Description
The count() function returns the number of records in a group as a 64-bit integer (long).
If EXPR is not specified, it returns the total number of records in the group. If EXPR is specified, it counts only records where the expression's return value is not null.
This function can only be used in aggregation commands such as stats and timechart.
Error codes
N/A
Usage examples
To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.
-
Count the total number of requests
table WEB_APACHE_SAMPLE | stats count -
Count the number of requests per HTTP method
table WEB_APACHE_SAMPLE | stats count by method -
Null value handling — count only non-null values
json "[{'val': 10}, {'val': null}, {'val': 30}]" | stats count(val) | # count(val): 2
Compatibility
The count() function has been available since before Logpresso Sonar 4.0.