> For the complete documentation index, see [llms.txt](https://docs.nexthink.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nexthink.com/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-functions.md).

# 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" %}

```
devices during past 7d 
| include device_performance.system_crashes during past 7d 
| compute number_of_crashes = number_of_system_crashes.sum()
```

{% endcode %}

#### countif()

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

```
collaboration.sessions during past 24h
| 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" %}

```
devices
| summarize total_cost = count() * 2000
| list total_cost.as(format = currency, code  = USD)
```

{% endcode %}

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

#### time\_elapsed()

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

```
devices
| where operating_system.last_update.time_elapsed() > 15d
```

{% endcode %}

#### 時間()

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

```
device_performance.events during past 24h
| 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.avg()</code> および <code>.count.avg()</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" %}

```
devices during past 7d
| with device_performance.events during past 7d
| compute avg_free_memory = free_memory.avg()
| where avg_free_memory < 3GB
```

{% endcode %}

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

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

**例:**

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

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

```
devices
| include device_performance.boots
| where type == fast_startup
| compute time_since_last_fast_startup = time.last().time_elapsed()
```

{% endcode %}

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
