Skip to main content
Count the number of values within the requested window. For more information on usage, please refer to Window Functions

Syntax

COUNT( <value> ) OVER ( [ PARTITION BY <partition_by> ] )

Parameters

ParameterDescriptionSupported input types
<value>A value used for the COUNT() function.Any numeric type
<partition_by>An expression used for the PARTITION BY clause.Any

Return Type

NUMERIC

Example

The following example counts how many players registered on each day by using COUNT as a window function partitioned by registration date.
SELECT
    registeredon,
    agecategory,
    COUNT(agecategory) OVER (PARTITION BY registeredon) AS count_of_players
FROM
    (VALUES
        ('2020-11-15'::DATE, 'Junior'),
        ('2020-11-15'::DATE, 'Senior'),
        ('2020-11-15'::DATE, 'Adult'),
        ('2020-11-16'::DATE, 'Junior'),
        ('2020-11-16'::DATE, 'Adult')
    ) AS t(registeredon, agecategory)
ORDER BY registeredon, agecategory;
registeredon dateagecategory textcount_of_players long
2020-11-15Adult3
2020-11-15Junior3
2020-11-15Senior3
2020-11-16Adult2
2020-11-16Junior2

Rows: 5Execution time: 2.39ms