# sumCount (/docs/reference/sql/aggregate-functions/sumcount)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

Calculates the sum of the numbers and counts the number of rows at the same time. The function is used by RawTree 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.

**See also**

* [`optimize_syntax_fuse_functions`](/reference/settings/session-settings/optimize#optimize_syntax_fuse_functions) setting.

**Syntax**

```sql
sumCount(x)
```

**Arguments**

* `x` — Input value. [`(U)Int*`](/reference/data-types/int-uint) or [`Float`](/reference/data-types/float) or [`Decimal`](/reference/data-types/decimal)

**Returned value**

Returns a tuple `(sum, count)`, where `sum` is the sum of numbers and `count` is the number of rows with not-NULL values. [`Tuple`](/reference/data-types/tuple)

**Examples**

**Basic usage**

```sql title=Query
CREATE TABLE s_table (x Int8) ENGINE = Log;
INSERT INTO s_table SELECT number FROM numbers(0, 20);
INSERT INTO s_table VALUES (NULL);
SELECT sumCount(x) FROM s_table;
```

```text title=Response
┌─sumCount(x)─┐
│ (190,20)    │
└─────────────┘
```

*Introduced in version 21.6.0.*
