# NQL文法の概要

## テーブルの指定 <a href="#nqlsyntaxoverview-specifyingtable" id="nqlsyntaxoverview-specifyingtable"></a>

すべてのNQLクエリは、データを選択するテーブルを指定する簡潔なステートメントから始まります。 テーブルを指定する構文は次のとおりです:

`<namespace>.<table>`

例えば、execution名前空間のeventsテーブル内のすべてのレコードをリストするには、次のステートメントになります:

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

```
execution.events
```

{% endcode %}

### 構文ショートカット <a href="#nqlsyntaxoverview-syntaxshortcuts" id="nqlsyntaxoverview-syntaxshortcuts"></a>

名前空間とテーブルを入力する代わりに、定義済みのショートカットを使用することもできます。 最初に名前空間を入力せずに、テーブル名のみを入力して以下のテーブルからデータを取得します:

| 名前空間        | Areas       | ショートカット        |
| ----------- | ----------- | -------------- |
| application | \[アプリケーション] | `applications` |
| バイナリー       | バイナリ        | `バイナリ`         |
| キャンペーン      | キャンペーン      | `キャンペーン`       |
| device      | デバイス        | `デバイス`         |
| ユーザー        | ユーザー        | `ユーザー`         |

例えば、`device.devices`の代わりに`devices`と入力して、device名前空間のdevicesテーブル内のすべてのレコードをリストできます。

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

```
デバイス
```

{% endcode %}

テーブルからデータをクエリする際に、結果に含めるテーブルフィールドを指定する必要はありません。 システムは、レコードを識別するうえで最も関連性のあるデフォルトフィールドを含めます。 特定のテーブルに含まれるフィールドに関する詳細については、NQLデータモデルページを参照してください。 特定のテーブル内の他のフィールドにアクセスするには[NQLリスト](/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-keywords/nql-list.md)キーワードを使用します。

## 時間枠の指定 <a href="#nqlsyntaxoverview-specifyingtimeframe" id="nqlsyntaxoverview-specifyingtimeframe"></a>

NQLステートメントのテーブル名のすぐ後に時間枠を選択することで、特定の期間にわたって結果をフィルタリングできます。 必要に応じて、さまざまなデータ選択形式と時間精度から選択できます。 例えば、以下のように過去数日を指定できます:

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

```
execution.crashes 過去7日間
```

{% endcode %}

または特定の日付:

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

```
execution.crashes 2024年2月8日
```

{% endcode %}

また、次のインベントリオブジェクトをクエリするときに時間選択を使用することもできます: devices, users, binaries。 インベントリオブジェクトの時間枠を指定すると、システムはオブジェクトの活動の背後にあるイベントを参照します。

例えば、次のクエリは同じデータセットを参照します。

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

```
devices 過去7日間
```

{% endcode %}

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

```
devices 
| with device_performance.events 過去7日間
```

{% endcode %}

時間選択形式に関する詳細については、[NQL時間選択](/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-syntax-overview/nql-time-selection.md)を参照してください。

## クエリ結果のカスタマイズ <a href="#nqlsyntaxoverview-customizingqueryresults" id="nqlsyntaxoverview-customizingqueryresults"></a>

テーブルと時間枠を指定した後、[キーワード](/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-keywords.md)、[演算子](/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-operators.md)、[関数](/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-functions.md)を使用してシステムに追加の指示を提供することで、クエリをさらに改善できます。 これらの改善により、結果を整理、フィルタリング、または集約して、より包括的な洞察を得ることができます。

たとえば：

1. `where`句を使用して結果をフィルタリング

   <pre data-overflow="wrap" data-line-numbers><code>binaries 過去24時間
   | where binary.name == "dllhost.exe"
   </code></pre>
2. `list`句を使用して表示する特定のデータを選択

   <pre data-overflow="wrap" data-line-numbers><code>binaries 過去24時間
   | where binary.name == "dllhost.exe"
   | list name, version, platform, architecture, size
   </code></pre>
3. ソート... `desc`句を使用して結果を順序付け

   <pre data-overflow="wrap" data-line-numbers><code>binaries 過去24時間
   | where binary.name == "dllhost.exe"
   | list name, version, platform, architecture, size
   | sort size desc
   </code></pre>
4. `limit`句を使用して最大結果数を設定

   <pre data-overflow="wrap" data-line-numbers><code>binaries 過去24時間
   | where binary.name == "dllhost.exe"
   | list name, version, platform, architecture, size
   | sort size desc
   | limit 10
   </code></pre>

特定の指示については、[NQLキーワード](/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-keywords.md)セクションを参照してください。

## パターンマッチング <a href="#nqlsyntaxoverview-patternmatching" id="nqlsyntaxoverview-patternmatching"></a>

テキストフィルタに`*`や`?`のようなワイルドカード文字を使用します。

`*` 任意の文字列を置き換えます

`?` 任意の1文字を置き換えます

例えば、名前が**dll**で始まり、**.exe**で終わるすべてのバイナリをリストするクエリは次のようになります:

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

```
binaries 過去24時間
| where binary.name == "dll*.exe"
| list size,name,version 
| sort size desc 
| limit 100
```

{% endcode %}

* [NQL時間選択](/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-syntax-overview/nql-time-selection.md)
* [NQLデータタイプ](/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-syntax-overview/nql-data-types.md)

## エスケープ文字について

リテラル文字列では、バックスラッシュ（`\`）をエスケープ文字として使用します。

一般的なエスケープシーケンス：

* `\"`：文字列リテラル内の二重引用符をエスケープします
* `\'`：文字列リテラル内の単一引用符をエスケープします
* `\\`：バックスラッシュ文字そのものをエスケープします
* `\\u####`：特殊文字の Unicode エスケープシーケンス

次の例は、引用符（`"`）に使用される `\u0022` など、一連の Unicode 文字をエスケープする方法を示しています：

```
devices
| with execution.events
| where binary.name in ["\\u0022", "\\u003c", "\\u005f"]
```

次の例は、`C:\Program Files\` のような Windows のファイルパスを検索する際にエスケープ文字を使用する方法を示しています：

```
devices
| compute program_files_path = "C:\\Program Files\\"
| where program_files_path != null
```

次の例は、`HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft` のような Windows のレジストリパスを検索する際にエスケープ文字を使用する方法を示しています：

```
devices
| include remote_action.get_windows_registry_key_values_windows.executions
| where inputs.RegistryKey1 == "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft"
| compute c1 = outputs.ValueData1.last() | where c1 != null
```

## コメント

NQLクエリでコメントを使用して、実行中に無視される説明メモを含めます。 コメントはクエリの意図を明確にし、読みやすく、保守しやすく、理解しやすくします。

コメントを始めるには`/*`で始め、終わるには`*/`を使用します。 これらのシンボル間のすべてのテキストは、実行中に無視されます。

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

```
devices 過去7日間 
/* このコメントは複数行にわたりますが、無視されます */
| list device.name, device.entity
```

{% endcode %}

### コメント用のキーボードショートカット

NQLクエリでコメントを追加または削除するための以下のキーボードショートカットを使用してください。

#### 行ベースのコメント

現在の行または選択された複数行にコメントをトグルします。

以下のショートカットは、カーソルが置かれている行全体をコメントブロックで囲むか、または削除します。 複数行が選択されている場合、フル行を1つのコメントブロックで囲みます。 **Windows**: `Ctrl + /`を押します

* **macOS**: `Cmd + /`を押します
* インラインまたはブロックコメント

#### 選択したコードにコメントをトグルします。

以下のショートカットは、選択が途中で始まったり終了したりしても、ハイライトされたコード部分をコメントブロックで囲むか、削除します。

Windows: `Shift + Alt + A`を押します macOS: `Shift + Option + A`を押します

* <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p>いずれかのショートカットを再度押すと、その操作で追加されたコメントブロックが削除されます。</p></div>
* macOS: `Shift + Option + A`を押す

有効なコメントの配置

### ただし、コメントが許可されていない特定のケースがあります。

このような場合には、NQLエディターがエラーを表示します。 無効なコメント配置の具体例は次の表に示されています。

無効なコメント配置の説明 例: 無効なコメント配置

<table data-header-hidden><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><code>|</code>とステートメントキーワードの間</td><td><code>devices | /* comment */ where name == "test"</code></td></tr><tr><td>式の内部</td><td><pre data-overflow="wrap"><code>devices | where name /* comment */ == "test"
</code></pre></td></tr><tr><td>演算子とオペランドの間</td><td><pre data-overflow="wrap"><code>devices | compute x = count /* comment */ ()
</code></pre></td></tr><tr><td>関数呼び出しの内部</td><td><pre data-overflow="wrap"><code>devices | summarize c = count() by /* comment */ 1d, start_time
</code></pre></td></tr><tr><td>関数呼び出しの内部に</td><td><pre data-overflow="wrap"><code>devices | summarize c = count() by /* comment */ 1日, start_time
</code></pre></td></tr></tbody></table>


---

# 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-syntax-overview.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.
