# πŸ“˜ Basic Usage of SQL Expressions in Grafana SQL expressions in Grafana let you perform lightweight SQL-like transformations on the results of other queries β€” directly within the panel. This is great for reshaping, renaming, filtering, and aggregating data without modifying the original datasource query. --- ## πŸ”§ How SQL Expressions Work SQL expressions operate on the output of **another query in the same panel**, referenced by its query letter (e.g., `A`, `B`). These expressions are parsed and executed by Grafana β€” not sent to an external database. --- ## πŸ“₯ Input Requirements To work correctly, SQL expressions must use data from a **backend datasource** (e.g., Prometheus, JSON API, GitHub, etc.). ### βœ… Accepted Inputs | Input Type | SQL Mapping Behavior | |-------------------------------------------------|----------------------------------------------------------------------------------| | **Single table-like frame (no labels)** | Used directly β€” **each field becomes a column in the SQL table**. | | **Full Long format** (e.g., `numeric_full_long`) | Maps directly as a flat table β€” no conversion needed. | | **Metric frame with `FrameMeta.Type`** (e.g., `TimeSeriesWide`, `TimeSeriesMulti`, `NumericWide`, `NumericMulti`) | Automatically **converted to `full_long` format**, then treated as a table. | ### ❌ Rejected Inputs - Queries that **lack `FrameMeta.Type` and are not a single flat table with no labels**. - Queries from **non-backend datasources** (e.g., local variables or dashboard-only sources). - Responses with ambiguous frame structures that cannot be interpreted as tables or convertible metrics. --- ## πŸ“¦ What’s in a `full_long` Format? When Grafana auto-converts a metric frame into a `full_long` table, the result typically includes: | Field | Description | |--------------------|------------------------------------------------------| | `time` | Timestamp column (if present) | | `__value__` | The numeric value | | `__metric__` | Metric name (e.g., `cpu`, `up`, etc.) | | `__display_name__` | Resolved display name for visualization (e.g., legend) | | `