# NQLインクルード

`include` 句を使うと、インベントリオブジェクトテーブルとイベントテーブルを結合することができます。 特定のオブジェクトにイベントが記録されていなくても、各オブジェクトごとにデータを返します。 メトリクスを計算する際に、すべてのオブジェクトを考慮に入れるようにするために使用します。

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

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

```
<object table> ...
| include <event table> ...
| compute <new metric name> = <metric>.<aggregation function>
...
```

{% endcode %}

### 例 <a href="#nqlinclude-example" id="nqlinclude-example"></a>

実行クラッシュを引き起こしたバイナリと、過去24時間におけるクラッシュの数をリストします。

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

```
binaries
| include execution.crashes during past 24h
| compute total_number_of_crashes = count()
| list total_number_of_crashes, name
| sort total_number_of_crashes desc
```

{% endcode %}

| クラッシュの数 | バイナリ名         |
| ------- | ------------- |
| 83      | lorem.exe     |
| 20      | bibendum.exe  |
| 10      | imperdiet.exe |
| 9       | tempor.exe    |
| 7       | egestas.exe   |
| 6       | semper.exe    |
| 6       | justo.exe     |

### 複数の「include」句の使用 <a href="#nqlinclude-usingmultipleincludeclauses" id="nqlinclude-usingmultipleincludeclauses"></a>

NQL クエリには複数の `include` 句を含めることができ、異なる条件で同じイベントテーブルを結合したり、複数の異なるイベントテーブルを結合することができます。

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

```
binaries
| include execution.crashes during past 1d
| compute total_number_of_crashes = count()
| include execution.events during past 1d
| compute sum_of_freezes = number_of_freezes.sum()
| list total_number_of_crashes, sum_of_freezes, name
| sort total_number_of_crashes desc
```

{% endcode %}

| クラッシュの数 | フリーズの合計 | バイナリ名        | MD5 ハッシュ                         |
| ------- | ------- | ------------ | -------------------------------- |
| 60      | 0       | odio.exe     | f32bd724cb4b8593c9789ec584eb38dc |
| 26      | 0       | volutpat.exe | 5ec62b81e594367fa20a3fbdf4e4e7f3 |
| 12      | 0       | eget.exe     | dc182b7939eba5ca8b1d64396b88fcd2 |
| 7       | 0       | euismod.exe  | 2d0c540521f7e5683487c42c6ff52479 |
| 7       | 0       | euismod.exe  | 2d0c540521f7e5683487c42c6ff52479 |
| 6       | 0       | aliquet.exe  | f4c4ad04db18ff1d225cbc43e864748a |
| 6       | 0       | vitae.exe    | bd85d77734d35c5ee00edeffc44e1dcd |

### ‘with’ と ‘include’ 句の目的を理解する <a href="#nqlinclude-understandingthepurposeofwithandincludeclauses" id="nqlinclude-understandingthepurposeofwithandincludeclauses"></a>

`include` と `with` キーワードは非常に似ていますが、目的が大きく異なります。

| キーワード     | 意味                                      | スコープ                       | 目的                             | 計算                          |
| --------- | --------------------------------------- | -------------------------- | ------------------------------ | --------------------------- |
| `with`    | イベントが記録されたオブジェクトのみを保持します                | 範囲を変更します                   | イベントのあるオブジェクトの値をフィルタリングして計算します | 常に値が計算され、追加されます             |
| `include` | イベントが記録されていないオブジェクトも含め、すべてのオブジェクトを保持します | 計算ステートメントがない場合、範囲に影響はありません | すべてのオブジェクトに対して値が計算される場合にのみ有用です | イベントがないオブジェクトには計算された値がありません |


---

# 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-keywords/nql-include.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.
