Other functions

In contrast to [`initialQueryID`](#initialQueryID) function, `queryID` can return different results on different shards.

**Syntax**

```
queryID()
```

**Aliases**: `query_id`

**Arguments**

- None.

**Returned value**

Returns the ID of the current query. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
CREATE TABLE tmp (str String) ENGINE = Log;
INSERT INTO tmp (*) VALUES ('a');
SELECT count(DISTINCT t) FROM (SELECT queryID() AS t FROM remote('127.0.0.{1..3}', currentDatabase(), 'tmp') GROUP BY queryID());
```

```
┌─count(DISTINCT t)─┐
│                 3 │
└───────────────────┘
```

## revision[​](#revision "Direct link to revision")

Introduced in: v22.7.0

Returns the current ClickHouse server revision.

**Syntax**

```
revision()
```

**Arguments**

- None.

**Returned value**

Returns the current ClickHouse server revision. [`UInt32`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT revision()
```

```
┌─revision()─┐
│      54485 │
└────────────┘
```

## rowNumberInAllBlocks[​](#rowNumberInAllBlocks "Direct link to rowNumberInAllBlocks")

Introduced in: v1.1.0

Returns a unique row number for each row processed.

**Syntax**

```
rowNumberInAllBlocks()
```

**Arguments**

- None.

**Returned value**

Returns the ordinal number of the row in the data block starting from `0`. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT rowNumberInAllBlocks()
FROM
(
    SELECT *
    FROM system.numbers_mt
    LIMIT 10
)
SETTINGS max_block_size = 2
```

```
┌─rowNumberInAllBlocks()─┐
│                      0 │
│                      1 │
└────────────────────────┘
┌─rowNumberInAllBlocks()─┐
│                      4 │
│                      5 │
└────────────────────────┘
┌─rowNumberInAllBlocks()─┐
│                      2 │
│                      3 │
└────────────────────────┘
┌─rowNumberInAllBlocks()─┐
│                      6 │
│                      7 │
└────────────────────────┘
┌─rowNumberInAllBlocks()─┐
│                      8 │
│                      9 │
└────────────────────────┘
```

## rowNumberInBlock[​](#rowNumberInBlock "Direct link to rowNumberInBlock")

Introduced in: v1.1.0

For each [block](/docs/development/architecture#block) processed by `rowNumberInBlock`, returns the number of the current row.

The returned number starts from 0 for each block.

**Syntax**

```
rowNumberInBlock()
```

**Arguments**

- None.

**Returned value**

Returns the ordinal number of the row in the data block starting from `0`. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT rowNumberInBlock()
FROM
(
    SELECT *
    FROM system.numbers_mt
    LIMIT 10
) SETTINGS max_block_size = 2
```

```
┌─rowNumberInBlock()─┐
│                  0 │
│                  1 │
└────────────────────┘
┌─rowNumberInBlock()─┐
│                  0 │
│                  1 │
└────────────────────┘
┌─rowNumberInBlock()─┐
│                  0 │
│                  1 │
└────────────────────┘
┌─rowNumberInBlock()─┐
│                  0 │
│                  1 │
└────────────────────┘
┌─rowNumberInBlock()─┐
│                  0 │
│                  1 │
└────────────────────┘
```

## runningAccumulate[​](#runningAccumulate "Direct link to runningAccumulate")

Introduced in: v1.1.0

Accumulates the states of an aggregate function for each row of a data block.

Deprecated

The state is reset for each new block of data.
Due to this error-prone behavior the function has been deprecated, and you are advised to use [window functions](/docs/sql-reference/window-functions) instead.
You can use setting [`allow_deprecated_error_prone_window_functions`](/docs/operations/settings/settings#allow_deprecated_error_prone_window_functions) to allow usage of this function.

**Syntax**

```
runningAccumulate(agg_state[, grouping])
```

**Arguments**

- `agg_state` — State of the aggregate function. [`AggregateFunction`](/docs/sql-reference/data-types/aggregatefunction)
- `grouping` — Optional. Grouping key. The state of the function is reset if the `grouping` value is changed. It can be any of the supported data types for which the equality operator is defined. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns the accumulated result for each row. [`Any`](/docs/sql-reference/data-types)

**Examples**

**Usage example with initializeAggregation**

```
WITH initializeAggregation('sumState', number) AS one_row_sum_state
SELECT
    number,
    finalizeAggregation(one_row_sum_state) AS one_row_sum,
    runningAccumulate(one_row_sum_state) AS cumulative_sum
FROM numbers(5);
```

```
┌─number─┬─one_row_sum─┬─cumulative_sum─┐
│      0 │           0 │              0 │
│      1 │           1 │              1 │
│      2 │           2 │              3 │
│      3 │           3 │              6 │
│      4 │           4 │             10 │
└────────┴─────────────┴────────────────┘
```

## runningConcurrency[​](#runningConcurrency "Direct link to runningConcurrency")

Introduced in: v21.3.0

Calculates the number of concurrent events.
Each event has a start time and an end time.
The start time is included in the event, while the end time is excluded.
Columns with a start time and an end time must be of the same data type.
The function calculates the total number of active (concurrent) events for each event start time.

Requirements

Events must be ordered by the start time in ascending order.
If this requirement is violated the function raises an exception.
Every data block is processed separately.
If events from different data blocks overlap then they can not be processed correctly.

Deprecated

It is advised to use [window functions](/docs/sql-reference/window-functions) instead.

**Syntax**

```
runningConcurrency(start, end)
```

**Arguments**

- `start` — A column with the start time of events. [`Date`](/docs/sql-reference/data-types/date) or [`DateTime`](/docs/sql-reference/data-types/datetime) or [`DateTime64`](/docs/sql-reference/data-types/datetime64)
- `end` — A column with the end time of events. [`Date`](/docs/sql-reference/data-types/date) or [`DateTime`](/docs/sql-reference/data-types/datetime) or [`DateTime64`](/docs/sql-reference/data-types/datetime64)

**Returned value**

Returns the number of concurrent events at each event start time. [`UInt32`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT start, runningConcurrency(start, end) FROM example_table;
```

```
┌──────start─┬─runningConcurrency(start, end)─┐
│ 2025-03-03 │                              1 │
│ 2025-03-06 │                              2 │
│ 2025-03-07 │                              3 │
│ 2025-03-11 │                              2 │
└────────────┴────────────────────────────────┘
```

## runningDifference[​](#runningDifference "Direct link to runningDifference")

Introduced in: v1.1.0

Calculates the difference between two consecutive row values in the data block.
Returns `0` for the first row, and for subsequent rows the difference to the previous row.

Deprecated

Only returns differences inside the currently processed data block.
Because of this error-prone behavior, the function is deprecated.
It is advised to use [window functions](/docs/sql-reference/window-functions) instead.

You can use setting [`allow_deprecated_error_prone_window_functions`](/docs/operations/settings/settings#allow_deprecated_error_prone_window_functions) to allow usage of this function.

The result of the function depends on the affected data blocks and the order of data in the block.
The order of rows during calculation of `runningDifference()` can differ from the order of rows returned to the user.
To prevent that you can create a subquery with [`ORDER BY`](/docs/sql-reference/statements/select/order-by) and call the function from outside the subquery.
Please note that the block size affects the result.
The internal state of `runningDifference` state is reset for each new block.

**Syntax**

```
runningDifference(x)
```

**Arguments**