COUNT
Overview
The COUNT()
window function allows you to retrieve the number of records that meet a specific criteria. It can be used with all data types supported by Oxla.
Syntax
There are two available variants of that function:
COUNT(*)
: counts all rows in the target table, regardless of whether they contain NULL values or notCOUNT(expression)
: counts the number of non-NULL values in a specific column or expression
The syntax for this function is as follows:
The COUNT()
window function always return BIGINT
as an output, which represents the total number of rows in a table irrespective of the input types.
Parameters
expression
: the column or expression that the function operates on
Examples
For the needs of this section, we will create a winsales
table that stores the details of some sales transactions:
COUNT(*)
In this example, we will focus on executing the variant of this function that counts all rows in the target table:
The output of the code abote displays the sales ID, quantity and the count of all rows from the start of the data window:
COUNT(expression)
In this example, we will focus on executing the variant of this function that counts the number of non-NULL values in a specific expression:
Here is the output for the query presented above: