> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-parallel-read-in-order-multi-part.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> タイムスタンプの昇順で時系列をソートします。

# timeSeriesGroupArray

## timeSeriesGroupArray

導入バージョン: v25.8.0

時系列データを タイムスタンプ の昇順にソートします。

サンプルは次の 3 つの形式のいずれかで渡すことができます。

* 2 つの引数 `timestamp` と `value` として渡す形式。各行が単一のサンプルを保持します。
* タイムスタンプの配列と値の配列の 2 つとして渡す形式。各行が時系列全体を保持します。
* `(timestamp, value)` のタプルからなる単一の配列として渡す形式。各行が時系列全体を保持します。この形式は結果と同じ型であるため、`SimpleAggregateFunction` データ型でこの関数を使用できます。

複数のサンプルのタイムスタンプが同じ場合は、値が最大のサンプルのみが使用されます。NaN 値は他のすべての値よりも優先度が低いため、このタイムスタンプのすべてのサンプルが NaN の場合にのみ使用されます。

<Note>
  この関数はプライベートプレビューです。`enable_time_series_aggregate_functions=true` を設定して有効にしてください。
</Note>

**構文**

```sql theme={null}
timeSeriesGroupArray(timestamp, value)
timeSeriesGroupArray(samples)
```

**引数**

* `timestamp` — サンプルのタイムスタンプ。個別の値または配列を指定できます。[`UInt32`](/ja/reference/data-types/int-uint) または [`DateTime`](/ja/reference/data-types/datetime) または [`DateTime64`](/ja/reference/data-types/datetime64) または [`Array(UInt32)`](/ja/reference/data-types/array) または [`Array(DateTime)`](/ja/reference/data-types/array) または [`Array(DateTime64)`](/ja/reference/data-types/array)
* `value` — そのタイムスタンプに対応する時系列の値。個別の値または配列を指定できます。[`Float*`](/ja/reference/data-types/float) または [`Array(Float*)`](/ja/reference/data-types/array)
* `samples` — `(timestamp, value)` のタプルの配列として渡される時系列のサンプル。タプルの要素の型は上記のタイムスタンプおよび値の型です。[`Array(Tuple(T1, T2))`](/ja/reference/data-types/array)

**戻り値**

タイムスタンプの昇順にソートされた `(timestamp, value)` のタプルの配列を返します。[`Array(Tuple(T1, T2))`](/ja/reference/data-types/array)

**例**

**個別の値を使った基本的な使い方**

```sql title=Query theme={null}
SET enable_time_series_aggregate_functions = 1;
WITH
    [110, 120, 130, 140, 140, 100]::Array(UInt32) AS timestamps,
    [1, 6, 8, 17, 19, 5]::Array(Float32) AS values
SELECT timeSeriesGroupArray(timestamp, value)
FROM
(
    SELECT
        arrayJoin(arrayZip(timestamps, values)) AS ts_and_val,
        ts_and_val.1 AS timestamp,
        ts_and_val.2 AS value
);
```

```response title=Response theme={null}
┌─timeSeriesGroupArray(timestamp, value)─────┐
│ [(100,5),(110,1),(120,6),(130,8),(140,19)] │
└────────────────────────────────────────────┘
```

**タイムスタンプと値の複数のサンプルを、同じ長さの配列として渡す**

```sql title=Query theme={null}
SET enable_time_series_aggregate_functions = 1;
WITH
    [110, 120, 130, 140, 140, 100]::Array(UInt32) AS timestamps,
    [1, 6, 8, 17, 19, 5]::Array(Float32) AS values
SELECT timeSeriesGroupArray(timestamps, values);
```

```response title=Response theme={null}
┌─timeSeriesGroupArray(timestamps, values)───┐
│ [(100,5),(110,1),(120,6),(130,8),(140,19)] │
└────────────────────────────────────────────┘
```
