# NQL関数

関数は、データを集計、フォーマット、または抽出し、さらなる分析を可能にする定義済みの操作です。 これには、グループ化されたデータ内での合計、平均、カウントなどの操作が含まれます。

特定の関数に基づいて、次の方法で使用できます:

* `compute`
* `summarize`
* `list`
* `sort`
* `where`

## 構文 <a href="#nqlfunctions-syntax" id="nqlfunctions-syntax"></a>

{% code overflow="wrap" lineNumbers="true" %}

```
...<metric>.<function>.(<optional: function parameters>)
```

{% endcode %}

## 例

### 集計関数

#### sum()

{% code overflow="wrap" lineNumbers="true" %}

```
過去7日間のデバイス 
| 過去7日間における device_performance.system_crashes を含む 
| compute number_of_crashes = number_of_system_crashes.sum()
```

{% endcode %}

#### countif()

{% code overflow="wrap" lineNumbers="true" %}

```
過去24時間の collaboration.sessions
| summarize ratio_of_poor_calls = countif(session.audio.quality = poor or session.video.quality = poor) / count() by connection_type
```

{% endcode %}

### フォーマット関数

#### as()

{% code overflow="wrap" lineNumbers="true" %}

```
デバイス
| summarize total_cost = count() * 2000
| list total_cost.as(format = currency, code  = USD)
```

{% endcode %}

### タイムスタンプ関数

#### time\_elapsed()

{% code overflow="wrap" lineNumbers="true" %}

```
デバイス
| where operating_system.last_update.time_elapsed() > 15d
```

{% endcode %}

#### 時間()

{% code overflow="wrap" lineNumbers="true" %}

```
過去24時間の device_performance.events
| where start_time.hour() >= 9 and end_time.hour() <= 17
```

{% endcode %}

## 集計されたメトリクス <a href="#nqlfunctions-aggregatedmetrics" id="nqlfunctions-aggregatedmetrics"></a>

関数と集計されたメトリクスを区別することが重要です。データモデルには情報へのアクセスを簡略化する様々な集計メトリクスが含まれています。 これらはデータモデルのフィールドとして定義されています。

<table data-full-width="false"><thead><tr><th width="196">フィールド</th><th width="269">説明</th><th>例</th></tr></thead><tbody><tr><td><code>.avg</code></td><td>バケットに集計されたメトリックの平均値。</td><td><code>where unload_event.avg > 1.0</code></td></tr><tr><td><code>.sum</code></td><td>バケットに集計されたメトリックのすべての値の合計。</td><td><code>where unload_event.sum == 10</code></td></tr><tr><td><code>.count</code></td><td>バケット内に集計された値の数。</td><td><code>where unload_event.count &#x3C;= 4</code></td></tr><tr><td><code>.min</code></td><td>バケット内のメトリックの最小値。</td><td><code>where unload_event.min &#x3C; 1.0</code></td></tr><tr><td><code>.max</code></td><td>バケット内のメトリックの最大値。</td><td><code>where unload_event.max > 1.0</code></td></tr></tbody></table>

## スマート集計 <a href="#nqlfunctions-smartaggregates" id="nqlfunctions-smartaggregates"></a>

スマート集計は、基礎的な計算を抽象化する集計されたメトリックに対する集計です。 これはデータモデルのフィールドではありません。 クエリの実行中に、パーサーがオンザフライで計算します。

<table data-full-width="false"><thead><tr><th width="222">集計</th><th>説明</th></tr></thead><tbody><tr><td><code>.avg()</code></td><td>このメトリックの平均値。<br>これは <code>.sum.sum()</code> および <code>.count.sum()</code> に相当します。</td></tr><tr><td><code>.sum()</code></td><td>メトリックの全値の合計。<br>これは、<code>.sum.sum()</code> に相当します</td></tr><tr><td><code>.max()</code></td><td>メトリックの最大値。<br>これは <code>.max.max()</code> に相当します。</td></tr><tr><td><code>.min()</code></td><td>このメトリックの最小値。<br>これは <code>.min.min()</code> に相当します。</td></tr><tr><td><code>.p95()</code></td><td>メトリックの95パーセンタイル。</td></tr><tr><td><code>.p05()</code></td><td>メトリックの 5 パーセンタイル。</td></tr><tr><td><code>.count()</code></td><td>集計された値の数。<br>これは <code>.count.sum()</code> に相当します。</td></tr></tbody></table>

**例:**

平均で3GB未満の空きメモリを持つデバイスのリストを取得します。 次のクエリには、`free_memory.avg()` スマート集計が `計算` 条項に含まれています。 これは、`free_memory.avg` 集計済み指標と同じ基礎データポイントに基づいて平均空きメモリを計算します。 これは、`free_memory.avg.avg().` に相当します

{% code overflow="wrap" lineNumbers="true" %}

```
デバイス 過去7日間
| には device_performance.events 過去7日間
| 計算 avg_free_memory = free_memory.avg()
| 条件 avg_free_memory < 3GB
```

{% endcode %}

## 関数の連鎖 <a href="#nqlfunctions-chainingoffunctions" id="nqlfunctions-chainingoffunctions"></a>

同じフィールドに対して複数の関数を呼び出すことができます。 現在、システムは `time_elapsed()` 関数の連鎖をサポートしています。

**例:**

以下のクエリは、最後の高速起動以来経過時間のあるデバイスのリストを返します。

{% code overflow="wrap" lineNumbers="true" %}

```
デバイス
| には device_performance.boots
| 条件 type == fast_startup
| 計算 time_since_last_fast_startup = time.last().time_elapsed()
```

{% endcode %}

以下のセクションでは、使用ルールと例を含む利用可能な関数のリストを見つけることができます。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nexthink.com/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
