# NQLウィズ

`with` 句を使用すると、インベントリオブジェクトテーブルをイベントテーブルと結合できます。 特定のオブジェクトに対して少なくとも1つのイベントが記録されている場合にのみ、オブジェクトごとのデータを返します。 イベントに条件を設定してインベントリオブジェクトを照会するために使用します。

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

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

```
<object table> ...
| with <event table> ...
```

{% endcode %}

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

過去7日間に少なくとも1つのエラーが発生したすべてのデバイスを選択します。

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

```
devices
| with web.errors during past 7d
| list device.name, operating_system.name
```

{% endcode %}

| 名前              | OS名                                |
| --------------- | ---------------------------------- |
| device-54304276 | Windows 10 Pro 21H1 (64ビット)        |
| device-c0b53b3f | Windows 10 Enterprise 21H1 (64ビット) |
| device-71cedc8f | Windows 10 Enterprise 21H1 (64ビット) |
| device-dc98cd15 | Windows 10 Enterprise 21H1 (64ビット) |
| device-b5d55bd0 | Windows 10 Pro 21H1 (64ビット)        |
| device-706d3c09 | Windows 10 Pro 21H1 (64ビット)        |
| device-a56b63f1 | Windows 10 Enterprise 21H1 (64ビット) |
| device-259c7017 | Windows 10 Pro 20H2 (64ビット)        |
| device-d0ce2109 | Windows 10 Enterprise 21H1 (64ビット) |

### 新しいメトリックの計算 <a href="#nqlwith-computingnewmetric" id="nqlwith-computingnewmetric"></a>

`with` 句は `compute` 句と共に使用することができ、オブジェクトごとの新しい列にメトリックを追加します。 詳細は、[NQL compute](/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-keywords/nql-compute.md) のキーワードドキュメントページを参照してください。

### 複数の ‘with’ 句の使用 <a href="#nqlwith-usingmultiplewithclauses" id="nqlwith-usingmultiplewithclauses"></a>

NQL クエリには複数の `with` 句を含めることができます。

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

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

{% endcode %}

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

### データのフィルタリング <a href="#nqlwith-filteringdata" id="nqlwith-filteringdata"></a>

計算された値のみが `with` 句の外で利用可能です。 `devices` から始めると、そのテーブルのフィールドのみが他の文に使用できます。 `with` と `compute` を追加すると、新しいフィールドが利用可能になります。

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

```
devices
| with web.errors during past 7d
| compute total_errors_device = number_of_errors.sum()
| where total_errors_device > 10
| list device.name, total_errors_device
| sort total_errors_device desc
```

{% endcode %}

| 名前              | total\_errors\_device |
| --------------- | --------------------- |
| device-741da9be | 125                   |
| device-c91fa737 | 120                   |
| device-08469fee | 62                    |
| device-f2301dea | 51                    |
| device-9e07abe9 | 45                    |
| device-03680882 | 42                    |
| device-25c67269 | 42                    |
| device-f8586bb6 | 41                    |
| device-b5d55bd0 | 39                    |
| device-60ea7a88 | 39                    |


---

# 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-with.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.
