sumCount

Calculates the sum of the numbers and counts the number of rows at the same time. The function is used by ClickHouse query optimizer: if there are multiple sum, count or avg functions in a query, they can be replaced to single sumCount function to reuse the calculations. The function is rarely needed to use explicitly.

Syntax

  1. sumCount(x)

Arguments

Returned value

  • Tuple (sum, count), where sum is the sum of numbers and count is the number of rows with not-NULL values.

Type: Tuple.

Example

Query:

  1. CREATE TABLE s_table (x Int8) Engine = Log;
  2. INSERT INTO s_table SELECT number FROM numbers(0, 20);
  3. INSERT INTO s_table VALUES (NULL);
  4. SELECT sumCount(x) from s_table;

Result:

  1. ┌─sumCount(x)─┐
  2. (190,20)
  3. └─────────────┘

See also