Query Builder

[Edit this page](https://github.com/ClickHouse/clickhouse-docs/blob/main/docs/integrations/data-visualization/grafana/query-builder.md)

ClickHouse Supported

Any query can be run with the ClickHouse plugin.
The query builder is a convenient option for simpler queries, but for complicated queries you will need to use the [SQL Editor](#sql-editor).

All queries in the query builder have a [query type](#query-types), and require at least one column to be selected.

The available query types are:

- [Table](#table): the simplest query type for showing data in table format. Works well as a catch-all for both simple and complex queries containing aggregate functions.
- [Logs](#logs): optimized for building queries for logs. Works best in explore view with [defaults configured](/docs/integrations/grafana/config#logs).
- [Time Series](#time-series): best used for building time series queries. Allows selecting a dedicated time column and adding aggregate functions.
- [Traces](#traces): optimized for searching/viewing traces. Works best in explore view with [defaults configured](/docs/integrations/grafana/config#traces).
- [SQL Editor](#sql-editor): the SQL Editor can be used when you want full control over the query. In this mode, any SQL query can be executed.

## Query types[​](#query-types "Direct link to Query types")

The *Query Type* setting will change the layout of the query builder to match the type of query being built.
The query type also determines which panel is used when visualizing data.

### Table[​](#table "Direct link to Table")

The most flexible query type is the table query. This is a catch-all for the other query builders designed to handle simple and aggregate queries.

|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Field Description|  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Builder Mode Simple queries exclude Aggregates and Group By, while aggregate queries include these options.|  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Columns The selected columns. Raw SQL can be typed into this field to allow for functions and column aliasing.|  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Aggregates A list of [aggregate functions](/docs/sql-reference/aggregate-functions). Allows for custom values for function and column. Only visible in Aggregate mode.| Group By A list of [GROUP BY](/docs/sql-reference/statements/select/group-by) expressions. Only visible in Aggregate mode.| Order By A list of [ORDER BY](/docs/sql-reference/statements/select/order-by) expressions.| Limit Appends a [LIMIT](/docs/sql-reference/statements/select/limit) statement to the end of the query. If set to `0` then it will be excluded. Some visualizations might need this set to `0` to show all the data.| Filters A list of filters to be applied in the `WHERE` clause. | | | | | | | | | | | | | | | |

This query type will render the data as a table.

### Logs[​](#logs "Direct link to Logs")

The logs query type offers a query builder focused on querying logs data.
Defaults can be configured in the data source's [log configuration](/docs/integrations/grafana/config#logs) to allow the query builder to be pre-loaded with a default database/table and columns.
OpenTelemetry can also be enabled to auto select the columns according to a schema version.

**Time** and **Level** filters are added by default, along with an Order By for the Time column.
These filters are tied to their respective fields, and will update as the columns are changed.
The **Level** filter is excluded from the SQL by default, changing it from the `IS ANYTHING` option will enable it.

The logs query type supports [data links](#data-links).

|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Field Description|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Use OTel Enables OpenTelemetry columns. Will overwrite the selected columns to use columns defined by the selected OTel schema version (Disables column selection).|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Columns Extra columns to be added to the log rows. Raw SQL can be typed into this field to allow for functions and column aliasing.|  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Time The primary timestamp column for the log. Will display time-like types, but allows for custom values/functions.|  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Log Level Optional. The *level* or *severity* of the log. Values typically look like `INFO`, `error`, `Debug`, etc.| Message The log message content.|  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | | Order By A list of [ORDER BY](/docs/sql-reference/statements/select/order-by) expressions.| Limit Appends a [LIMIT](/docs/sql-reference/statements/select/limit) statement to the end of the query. If set to `0` then it will be excluded, but this isn't recommended for large log datasets.| Filters A list of filters to be applied in the `WHERE` clause.| Message Filter A text input for conveniently filtering logs using a `LIKE %value%`. Excluded when input is empty. | | | | | | | | | | | | | | | | | | | |

  

This query type will render the data in the logs panel along with a logs histogram panel at the top.

Extra columns that are selected in the query can be viewed in the expanded log row:

### Time series[​](#time-series "Direct link to Time series")

The time series query type is similar to [table](#table), but with a focus on time series data.

The two views are mostly the same, with these notable differences:

- A dedicated *Time* field.
- In Aggregate mode, a time interval macro is automatically applied along with a Group By for the Time field.
- In Aggregate mode, the "Columns" field is hidden.
- A time range filter and Order By are automatically added for the **Time** field.

Is your visualization missing data?

In some cases the time series panel will appear to be cut off because the limit defaults to `1000`.

Try removing the `LIMIT` clause by setting it to `0` (if your dataset allows).