Skip to content

COUNT_IF

COUNT_IF

Compute the total number of occurrences of true in a column/group/window of booleans. For example:

SELECT COUNT_IF(A) FROM table1

Is equivalent to

SELECT SUM(CASE WHEN A THEN 1 ELSE 0 END) FROM table1

Note

When used as a window function with an ORDER BY clause but no window frame, ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW is used by default.