count
Learn more about the Cortex Query Language count function used with both comp and windowcomp stages.
Syntax
comp stage
comp count([<field>]) [as <alias>] by <field_1>,<field_2> [addrawdata = true|false [as <target field>]]windowcomp stage
windowcomp count([<field>]) [by <field> [,<field>,...]] [sort [asc|desc] <field1> [, [asc|desc] <field2>,...]] [between 0|null|<number>|-<number> [and 0|null|<number>|-<number>] [frame_type=range]] [as <alias>] Description
The count() function is used to return a single count for the number of rows either for a field over a group of rows, where only the number of non-null values found are returned, or without a field to count the number of rows, including null values. The function syntax and application is based on the preceding stage:
comp stage
When the count aggregation function is used with a comp stage, the function returns one of the following:
With a field: Returns a single count for the number of non-null rows, for all records that contain matching values for the fields identified in the
byclause.Without a field: Counts the number of rows and includes null values.
In addition, you can configure whether the raw data events are displayed by setting addrawdata to either true or false (default), which are used to configure the final comp results. When including raw data events in your query, the query runs for up to 50 fields that you define and displays up to 100 events.
Use count_distinct to retrieve the number of unique values in the result set.
windowcomp stage
When the count aggregate function is used with a windowcomp stage, the function returns one of the following:
With a field: Returns a single count for the number of non-null rows for all records that contain matching values for the fields identified using a combination of the
byclause,sort, andbetweenwindow frame clause. The results are provided in a new column in the results table.Without a field: Counts the number of rows and includes null values.
Examples
Last updated
Was this helpful?
