ClickHouse/docs/en/sql-reference/aggregate-functions/reference/sumcount.md

45 lines
1003 B
Markdown
Raw Normal View History

2021-05-24 17:44:53 +00:00
---
toc_priority: 142
---
# sumCount {#agg_function-sumCount}
2021-05-25 13:05:08 +00:00
Calculates the sum of the numbers and counts the number of rows at the same time.
2021-05-24 17:44:53 +00:00
**Syntax**
``` sql
sumCount(x)
```
**Arguments**
2021-05-25 13:05:08 +00:00
- `x` — Input value, must be [Integer](../../../sql-reference/data-types/int-uint.md), [Float](../../../sql-reference/data-types/float.md), or [Decimal](../../../sql-reference/data-types/decimal.md).
2021-05-24 17:44:53 +00:00
**Returned value**
- Tuple `(sum, count)`, where `sum` is the sum of numbers and `count` is a counts the number of rows or not-NULL values.
Type: [Tuple](../../../sql-reference/data-types/tuple.md).
**Example**
Query:
``` sql
2021-05-25 13:05:08 +00:00
CREATE TABLE test (x Int8) Engine = Log;
INSERT INTO test SELECT number FROM numbers(1, 20);
SELECT sumCount(x) from test;
2021-05-24 17:44:53 +00:00
```
Result:
``` text
2021-05-25 13:05:08 +00:00
┌─sumCount(a)─┐
│ (210,20) │
└─────────────┘
```
**See also**
2021-05-25 13:11:58 +00:00
- [optimize_fuse_sum_count_avg](../../../operations/settings/settings.md#optimize_fuse_sum_count_avg) setting.