The COUNT function returns the number of rows in a SQL expression.
COUNT(*) [OVER (...)]
COUNT([DISTINCT] expression) [OVER (...)]
SELECT
COUNT(*) AS count_all_rows,
COUNT(x) AS count_x,
COUNT(DISTINCT x) AS count_all_unique_values_of_x
FROM
UNNEST([1, 2, 2, 5, NULL]) AS x
The example above shows three different ways COUNT can be used.
COUNT can also be used as a window function. The below example runs the count function for each value of x.
SELECT
x,
COUNT(*) OVER (PARTITION BY x) AS count_all_rows,
COUNT(x) OVER (PARTITION BY x) AS count_x,
COUNT(DISTINCT x) OVER (PARTITION BY x) AS count_unique_x
FROM
UNNEST([1, 2, 2, 5, NULL]) AS x