docs/docs/en/data-visualization/guide/sql-data-query.md
In the Data query panel, switch to SQL mode, write and run the query, and use the returned result directly for chart mapping and rendering.
Example: order amount by month
SELECT
TO_CHAR(order_date, 'YYYY-MM') as mon,
SUM(total_amount) AS total
FROM "order"
GROUP BY mon
ORDER BY mon ASC
LIMIT 100;
Data supports pagination; you can switch between Table and JSON to check column names and types.
SELECT
TO_CHAR(order_date, 'YYYY-MM') as mon, -- dimension field in the first column
SUM(total_amount) AS total -- measure field afterwards
Click the x button at the top‑right of the SQL editor to choose context variables.
After confirming, the variable expression is inserted at the cursor (or replaces the selected text).
For example, {{ ctx.user.createdAt }}. Do not add extra quotes.
For more examples, see the NocoBase Demo app
Recommendations:
LIMIT to reduce returned rows and speed up preview.